#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 *);
char tolower(char);
char toupper(char);
char *trim(char *);
char *normalize_name(char *name) {
  int len;
  name = trim(name);
  len = strlen(name);
  name[0] = toupper(name[0]);
  for (int i = 1; i < len; i++)
    name[i] = tolower(name[i]);
  return name;
}


x86 assembly (clang, -O0):
<normalize_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <trim@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <normalize_name+0x78>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <normalize_name+0x40>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_name>:
push   %rbp
push   %r14
push   %rbx
call   1050 <trim@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
cmp    $0x2,%ebp
jl     1185 <normalize_name+0x45>
mov    %ebp,%r14d
mov    $0x1,%ebp
nopl   (%rax)
movsbl (%rbx,%rbp,1),%edi
call   1060 <tolower@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1170 <normalize_name+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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