#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char toupper(int);
void strucpy(char *p, const char *s, int n) {
  int c;
  int i;
  for (i = 0; i < n && (c = s[i]); ++i)
    p[i] = toupper(c);
}


x86 assembly (clang, -O0):
<strucpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    1153 <strucpy+0x43>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1163 <strucpy+0x53>
jmp    1186 <strucpy+0x76>
mov    -0x18(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <strucpy+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strucpy>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    114b <strucpy+0x3b>
mov    %rsi,%r15
mov    %rdi,%r14
mov    %edx,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
test   %edi,%edi
je     114b <strucpy+0x3b>
call   1030 <toupper@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <strucpy+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @strucpy(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %30, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
store i32 %19, i32* %7
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %13, %9
%22 = phi i1 [ false, %9 ], [ %20, %13 ]
br i1 %22, label %23, label %33
23: ; preds = %21
%24 = load i32, i32* %7
%25 = call signext i8 @toupper(i32 %24)
%26 = load i8*, i8** %4
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %23
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %9
33: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @strucpy(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %12
%8 = phi i64 [ 0, %5 ], [ %16, %12 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %7
%13 = sext i8 %10 to i32
%14 = tail call signext i8 @toupper(i32 %13)
%15 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %14, i8* %15
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %18, label %7
18: ; preds = %7, %12, %3
ret void
}