#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int toupper(char);
int main(void) {
  printf("Enter name: ");
  char *name = malloc(128 * sizeof(char));
  fgets(name, 128, stdin);
  printf("%c", toupper(name[0]));
  for (int i = 1, n = strlen(name); i < n; i++) {
    if (name[i] == ' ') {
      while (name[i] == ' ')
        i++;
      printf("%c", toupper(name[i]));
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    123e <main+0xee>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    122b <main+0xdb>
jmp    11e7 <main+0x97>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    120a <main+0xba>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <main+0x97>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1230 <main+0xe0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <main+0x71>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
movsbl (%r15),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     1210 <main+0xb0>
mov    %eax,%ebp
mov    %r15,%r14
add    $0x1,%r14
mov    $0x1,%ebx
jmp    11d7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
cmp    %ebp,%ebx
jge    1210 <main+0xb0>
movslq %ebx,%rax
cmpb   $0x20,(%r15,%rax,1)
jne    11d0 <main+0x70>
add    %r14,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rax),%ecx
add    $0x1,%ebx
add    $0x1,%rax
cmp    $0x20,%cl
je     11f0 <main+0x90>
movsbl %cl,%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Enter name: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @malloc(i32 128)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 128, i32 %8)
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = call i32 @toupper(i8 signext %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 1, i32* %3
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %4
br label %17
17: ; preds = %50, %0
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %53
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 32
br i1 %28, label %29, label %49
29: ; preds = %21
br label %30
30: ; preds = %38, %29
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 32
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %30
41: ; preds = %30
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @toupper(i8 signext %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %41, %21
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %17
53: ; preds = %17
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [13 x i8] c"Enter name: \00"
@stdin = global i32 0
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %2, i32 128, i32 %3)
%5 = load i8, i8* %2
%6 = tail call i32 @toupper(i8 signext %5)
%7 = tail call i32 @putchar(i32 %6)
%8 = tail call i32 @strlen(i8* %2)
%9 = icmp sgt i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %28, %0
%11 = tail call i32 @putchar(i32 10)
ret i32 0
12: ; preds = %0, %28
%13 = phi i32 [ %30, %28 ], [ 1, %0 ]
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 32
br i1 %17, label %18, label %28
18: ; preds = %12, %18
%19 = phi i64 [ %20, %18 ], [ %14, %12 ]
%20 = add i64 %19, 1
%21 = getelementptr inbounds i8, i8* %2, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 32
br i1 %23, label %18, label %24
24: ; preds = %18
%25 = trunc i64 %20 to i32
%26 = tail call i32 @toupper(i8 signext %22)
%27 = tail call i32 @putchar(i32 %26)
br label %28
28: ; preds = %12, %24
%29 = phi i32 [ %25, %24 ], [ %13, %12 ]
%30 = add nsw i32 %29, 1
%31 = icmp slt i32 %30, %8
br i1 %31, label %12, label %10
}