#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__ isalpha(int);
scalar_t__ islower(int);
char *strdup(char *);
int strlen(char *);
char toupper(int);
char *toUpperCase(char *in) {
  char *copy = strdup(in);
  int i, n, c;
  n = strlen(copy);
  for (i = 0; i < n; i++) {
    c = copy[i];
    if (isalpha(c) && islower(c)) {
      copy[i] = toupper(c);
    }
  }
  return copy;
}


x86 assembly (clang, -O0):
<toUpperCase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e3 <toUpperCase+0x93>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
je     11d0 <toUpperCase+0x80>
mov    -0x1c(%rbp),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     11d0 <toUpperCase+0x80>
mov    -0x1c(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d5 <toUpperCase+0x85>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117c <toUpperCase+0x2c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toUpperCase>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1070 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11b3 <toUpperCase+0x63>
mov    %eax,%r14d
xor    %ebx,%ebx
jmp    1189 <toUpperCase+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r14
je     11b3 <toUpperCase+0x63>
movsbl (%r15,%rbx,1),%ebp
mov    %ebp,%edi
call   1060 <isalpha@plt>
test   %rax,%rax
je     1180 <toUpperCase+0x30>
mov    %ebp,%edi
call   1030 <islower@plt>
test   %rax,%rax
je     1180 <toUpperCase+0x30>
mov    %ebp,%edi
call   1040 <toupper@plt>
mov    %al,(%r15,%rbx,1)
jmp    1180 <toUpperCase+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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