#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 */
int strlen(char const *);
char toupper(char const);
char *uc(const char *string) {
  static char out[1024];
  int ii, n = strlen(string);
  if (n > 1023)
    n = 1023;
  for (ii = 0; ii < n; ii++)
    out[ii] = toupper(string[ii]);
  out[ii] = '\0';
  return out;
}


x86 assembly (clang, -O0):
<uc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x3ff,-0x10(%rbp)
jle    114c <uc+0x2c>
movl   $0x3ff,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118e <uc+0x6e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
movslq -0xc(%rbp),%rcx
lea    0x2ec3(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <uc+0x33>
movslq -0xc(%rbp),%rcx
lea    0x2ea7(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e9c(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    1169 <uc+0x49>
cmp    $0x3ff,%eax
mov    $0x3ff,%r15d
cmovb  %eax,%r15d
xor    %ebx,%ebx
lea    0x2ef4(%rip),%r12
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx,%r12,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <uc+0x30>
jmp    116c <uc+0x4c>
xor    %r15d,%r15d
lea    0x2ecd(%rip),%rax
movb   $0x0,(%r15,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@uc.out = internal global [1024 x i8] zeroinitializer
define i8* @uc(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = icmp ult i32 %2, 1023
%6 = select i1 %5, i32 %2, i32 1023
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %14, %8 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call signext i8 @toupper(i8 signext %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* @uc.out, i64 0, i64 %9
store i8 %12, i8* %13
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = zext i32 %6 to i64
br label %18
18: ; preds = %1, %16
%19 = phi i64 [ %17, %16 ], [ 0, %1 ]
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* @uc.out, i64 0, i64 %19
store i8 0, i8* %20
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @uc.out, i64 0, i64 0)
}