#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 EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ is_letter(char);
scalar_t__ is_lower(char);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char to_upper(char);
int main() {
  char *sentence = "This is an example!";
  int length = strlen(sentence) + 1;
  char *upper_sentence = malloc(length * sizeof(char));
  strncpy(upper_sentence, sentence, length);
  printf("%s\n", sentence);
  for (int i = 0; i < length - 1; ++i) {
    char current = sentence[i];
    if (!is_letter(current)) {
      continue;
    }
    if (is_lower(current)) {
      upper_sentence[i] = to_upper(current);
    }
  }
  printf("%s\n", upper_sentence);
  free(upper_sentence);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1255 <main+0xd5>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%edi
call   1090 <is_letter@plt>
cmp    $0x0,%eax
jne    1219 <main+0x99>
jmp    1247 <main+0xc7>
movsbl -0x25(%rbp),%edi
call   1050 <is_lower@plt>
cmp    $0x0,%rax
je     1242 <main+0xc2>
movsbl -0x25(%rbp),%edi
call   10a0 <to_upper@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1247 <main+0xc7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e3 <main+0x63>
mov    -0x20(%rbp),%rsi
lea    0xdb4(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe71(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
lea    0xe58(%rip),%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
test   %r15d,%r15d
jle    1202 <main+0x82>
mov    %r15d,%r15d
xor    %ebx,%ebx
jmp    11d9 <main+0x59>
add    $0x1,%rbx
cmp    %rbx,%r15
je     1202 <main+0x82>
movsbl (%rbx,%r14,1),%ebp
mov    %ebp,%edi
call   1090 <is_letter@plt>
test   %eax,%eax
je     11d0 <main+0x50>
mov    %ebp,%edi
call   1050 <is_lower@plt>
test   %rax,%rax
je     11d0 <main+0x50>
mov    %ebp,%edi
call   10a0 <to_upper@plt>
mov    %al,(%r12,%rbx,1)
jmp    11d0 <main+0x50>
lea    0xe0b(%rip),%rdi
mov    %r12,%rsi
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"This is an example!\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = add nsw i32 %1, 1
%3 = tail call i8* @malloc(i32 %2)
%4 = tail call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %2)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = zext i32 %1 to i64
br label %13
9: ; preds = %25, %0
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%11 = tail call i32 @free(i8* %3)
%12 = load i32, i32* @EXIT_SUCCESS
ret i32 %12
13: ; preds = %7, %25
%14 = phi i64 [ 0, %7 ], [ %26, %25 ]
%15 = getelementptr inbounds [20 x i8], [20 x i8]* @.str, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @is_letter(i8 signext %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = tail call i64 @is_lower(i8 signext %16)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call signext i8 @to_upper(i8 signext %16)
%24 = getelementptr inbounds i8, i8* %3, i64 %14
store i8 %23, i8* %24
br label %25
25: ; preds = %19, %22, %13
%26 = add nuw nsw i64 %14, 1
%27 = icmp eq i64 %26, %8
br i1 %27, label %9, label %13
}