#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int EXIT_SUCCESS;
char *capitalize(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
int main() {
  char str[128];
  printf("Enter something: ");
  fgets(str, sizeof(str), stdin);
  if (strlen(str) > 0) {
    *(str + strlen(str) - 1) = '\0';
  };
  if (strlen(str) > 0) {
    printf("Original string:    %s\n", str);
    printf("Capitalized string: %s\n", capitalize(str));
  } else {
    printf("You didn't enter anything.\n");
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <fgets@plt>
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    11a4 <main+0x64>
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
movb   $0x0,-0x91(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    11f1 <main+0xb1>
lea    -0x90(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1060 <capitalize@plt>
mov    %rax,%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ff <main+0xbf>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    1191 <main+0x41>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    11cd <main+0x7d>
lea    0xe6d(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <capitalize@plt>
lea    0xe69(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d9 <main+0x89>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter something: \00"
@stdin = global i32 0
@.str.1 = [24 x i8] c"Original string: %s\0A\00"
@.str.2 = [24 x i8] c"Capitalized string: %s\0A\00"
@.str.3 = [28 x i8] c"You didn't enter anything.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 128, i32 %5)
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%8 = call i64 @strlen(i8* %7)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
store i8 0, i8* %15
br label %16
16: ; preds = %10, %0
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%24 = call i8* @capitalize(i8* %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %28
26: ; preds = %16
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter something: \00"
@stdin = global i32 0
@.str.1 = [24 x i8] c"Original string: %s\0A\00"
@.str.2 = [24 x i8] c"Capitalized string: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [27 x i8] c"You didn't enter anything.\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 128, i32 %4)
%6 = call i64 @strlen(i8* %2)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %6
%10 = getelementptr inbounds i8, i8* %9, i64 -1
store i8 0, i8* %10
br label %11
11: ; preds = %8, %0
%12 = call i64 @strlen(i8* %2)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%16 = call i8* @capitalize(i8* %2)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %20
18: ; preds = %11
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}