#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 *malloc(int);
int sfd_strlen(char const *);
char sfd_toupper(char const);
char *sfd_strupp(const char *s) {
  int i, l = sfd_strlen(s);
  char *s1 = malloc(l + 1);
  for (i = 0; i < l; i++)
    s1[i] = sfd_toupper(s[i]);
  s1[i + 1] = '\0';
  return s1;
}


x86 assembly (clang, -O0):
<sfd_strupp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sfd_strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1196 <sfd_strupp+0x66>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <sfd_toupper@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115e <sfd_strupp+0x2e>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sfd_strupp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
call   1030 <sfd_strlen@plt>
mov    %eax,%r12d
lea    0x1(%r12),%r14d
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
test   %r12d,%r12d
jle    117a <sfd_strupp+0x4a>
mov    %r12d,%r12d
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%edi
call   1040 <sfd_toupper@plt>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <sfd_strupp+0x30>
jmp    1180 <sfd_strupp+0x50>
mov    $0x1,%r14d
movb   $0x0,0x0(%r13,%r14,1)
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @sfd_strupp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @sfd_strlen(i8* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %5
store i32 0, i32* %3
br label %11
11: ; preds = %26, %1
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %29
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 @sfd_toupper(i8 signext %20)
%22 = load i8*, i8** %5
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %15
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %11
29: ; preds = %11
%30 = load i8*, i8** %5
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %5
ret i8* %35
}

LLVM IR (-O2):
define noalias i8* @sfd_strupp(i8* %0) {
%2 = tail call i32 @sfd_strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call signext i8 @sfd_toupper(i8 signext %11)
%13 = getelementptr inbounds i8, i8* %4, 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 = add i32 %2, 1
%18 = zext i32 %17 to i64
br label %19
19: ; preds = %1, %16
%20 = phi i64 [ %18, %16 ], [ 1, %1 ]
%21 = getelementptr inbounds i8, i8* %4, i64 %20
store i8 0, i8* %21
ret i8* %4
}