#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 */
scalar_t__ strlen(char *);
char toupper(char);
char *uppercase(char *s) {
  static char upcasestr[128 + 1];
  int i;
  for (i = 0; i < (int)strlen(s); i++)
    upcasestr[i] = toupper(s[i]);
  upcasestr[i] = '\0';
  return (upcasestr);
}


x86 assembly (clang, -O0):
<uppercase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    117f <uppercase+0x5f>
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    0x2ed2(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <uppercase+0x13>
movslq -0xc(%rbp),%rcx
lea    0x2eb6(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2eab(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uppercase>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    1161 <uppercase+0x41>
lea    0x2f06(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx,%r15,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <uppercase+0x20>
lea    0x2ed8(%rip),%rax
movb   $0x0,(%rbx,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@uppercase.upcasestr = internal global [129 x i8] zeroinitializer
define i8* @uppercase(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %1, %5
%6 = phi i64 [ %11, %5 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call signext i8 @toupper(i8 signext %8)
%10 = getelementptr inbounds [129 x i8], [129 x i8]* @uppercase.upcasestr, i64 0, i64 %6
store i8 %9, i8* %10
%11 = add nuw nsw i64 %6, 1
%12 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%13 = shl i64 %12, 32
%14 = ashr exact i64 %13, 32
%15 = icmp slt i64 %11, %14
br i1 %15, label %5, label %16
16: ; preds = %5
%17 = and i64 %11, 4294967295
br label %18
18: ; preds = %16, %1
%19 = phi i64 [ 0, %1 ], [ %17, %16 ]
%20 = getelementptr inbounds [129 x i8], [129 x i8]* @uppercase.upcasestr, i64 0, i64 %19
store i8 0, i8* %20
ret i8* getelementptr inbounds ([129 x i8], [129 x i8]* @uppercase.upcasestr, i64 0, i64 0)
}