#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 const *uniquestr(char *);
const char *strtoupper(const char *c) {
  if (c != NULL) {
    int n = strlen(c);
    char result[n + 1];
    int i;
    for (i = 0; i < n; i++) {
      result[i] = toupper(c[i]);
    }
    result[n] = '\0';
    return uniquestr(result);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strtoupper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11dc <strtoupper+0xac>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bb <strtoupper+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1183 <strtoupper+0x53>
mov    -0x38(%rbp),%rdi
movslq -0x14(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
call   1050 <uniquestr@plt>
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    11e4 <strtoupper+0xb4>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoupper>:
test   %rdi,%rdi
je     11bc <strtoupper+0x8c>
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %rsp,-0x30(%rbp)
lea    0x1(%r14),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %r14d,%r14d
jle    1198 <strtoupper+0x68>
mov    %r14d,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
movsbl (%r15,%r12,1),%edi
call   1030 <toupper@plt>
mov    %al,0x0(%r13,%r12,1)
add    $0x1,%r12
cmp    %r12,%rbx
jne    1180 <strtoupper+0x50>
movslq %r14d,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rdi
call   1050 <uniquestr@plt>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i8* @strtoupper(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %41
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %5
%17 = alloca i8, i64 %15
store i64 %15, i64* %6
store i32 0, i32* %7
br label %18
18: ; preds = %32, %10
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call signext i8 @toupper(i8 signext %27)
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %17, i64 %30
store i8 %28, i8* %31
br label %32
32: ; preds = %22
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %18
35: ; preds = %18
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %17, i64 %37
store i8 0, i8* %38
%39 = call i8* @uniquestr(i8* %17)
store i8* %39, i8** %2
%40 = load i8*, i8** %5
br label %42
41: ; preds = %1
store i8* null, i8** %2
br label %42
42: ; preds = %41, %35
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
define i8* @strtoupper(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %18, %12 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call signext i8 @toupper(i8 signext %15)
%17 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 %16, i8* %17
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %20, label %12
20: ; preds = %12, %3
%21 = sext i32 %4 to i64
%22 = getelementptr inbounds i8, i8* %8, i64 %21
store i8 0, i8* %22
%23 = call i8* @uniquestr(i8* %8)
br label %24
24: ; preds = %1, %20
%25 = phi i8* [ %23, %20 ], [ null, %1 ]
ret i8* %25
}