#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(char);
char *strupper(char *str) {
  static char buffer[1024];
  int i;
  for (i = 0; (str[i] != '\0' && i < (1024 - 1)); i++)
    buffer[i] = toupper(str[i]);
  buffer[i] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<strupper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     114a <strupper+0x3a>
cmpl   $0x3ff,-0xc(%rbp)
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    115a <strupper+0x4a>
jmp    1189 <strupper+0x79>
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    0x2ec8(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <strupper+0x13>
movslq -0xc(%rbp),%rcx
lea    0x2eac(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ea1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strupper>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1158 <strupper+0x48>
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x2f19(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%rbx,%r15,1)
lea    0x1(%rbx),%rcx
movzbl 0x1(%r14,%rbx,1),%eax
test   %al,%al
je     115a <strupper+0x4a>
cmp    $0x3fe,%rbx
mov    %rcx,%rbx
jb     1130 <strupper+0x20>
jmp    115a <strupper+0x4a>
xor    %ecx,%ecx
lea    0x2edf(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@strupper.buffer = internal global [1024 x i8] zeroinitializer
define i8* @strupper(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %15, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %9, %4 ], [ 0, %1 ]
%6 = phi i8 [ %11, %4 ], [ %2, %1 ]
%7 = tail call signext i8 @toupper(i8 signext %6)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* @strupper.buffer, i64 0, i64 %5
store i8 %7, i8* %8
%9 = add nuw nsw i64 %5, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
%13 = icmp ult i64 %5, 1022
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %4, label %15
15: ; preds = %4, %1
%16 = phi i64 [ 0, %1 ], [ %9, %4 ]
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* @strupper.buffer, i64 0, i64 %16
store i8 0, i8* %17
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @strupper.buffer, i64 0, i64 0)
}