#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 *concatenate(char *, char *);
int /*<<< orphan*/ free(char *);
int length(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
char *substring(char *, int, int);
int main() {
  char name[] = {'J', 'o', 'h', 'n', '\0'};
  char color[] = "blue";
  char *home_address = "P. Sherman 42 Wallaby Way, Sydney";
  printf("This is %s. He likes the color %s. He lives in %s.\n", name, color,
         home_address);
  printf("%s is a %d letters name.\n", name, length(name));
  char *str = concatenate("This is ", "a concatenated string.");
  printf("%s\n", str);
  str = substring("John Doe", 5, 3);
  printf("%s\n", str);
  free(str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9b(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xe96(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xe8e(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xe89(%rip),%al
mov    %al,-0xa(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x9(%rbp),%rsi
lea    -0xe(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x9(%rbp),%rdi
call   1040 <length@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1070 <concatenate@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea1(%rip),%rdi
mov    $0x5,%esi
mov    $0x3,%edx
call   1060 <substring@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0x14(%rsp)
movl   $0x6e686f4a,0x10(%rsp)
6e
movb   $0x0,0xc(%rsp)
movl   $0x65756c62,0x8(%rsp)
65
lea    0xeb4(%rip),%rdi
lea    0xe8b(%rip),%rcx
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <length@plt>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1070 <concatenate@plt>
lea    0xed2(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec2(%rip),%rdi
mov    $0x5,%esi
mov    $0x3,%edx
call   1060 <substring@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.name = [5 x i8] c"John\00"
@__const.main.color = [5 x i8] c"blue\00"
@.str = [34 x i8] c"P. Sherman 42 Wallaby Way, Sydney\00"
@.str.1 = [52 x i8] c"This is %s. He likes the color %s. He lives in %s.\0A\00"
@.str.2 = [26 x i8] c"%s is a %d letters name.\0A\00"
@.str.3 = [9 x i8] c"This is \00"
@.str.4 = [23 x i8] c"a concatenated string.\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [9 x i8] c"John Doe\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = alloca [5 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [5 x i8]* %2 to i8*
%7 = bitcast [5 x i8]* %3 to i8*
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %4
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %9, i8* %10)
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%14 = call i32 @length(i8* %13)
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %14)
%16 = call i8* @concatenate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%19 = call i8* @substring(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 5, i32 3)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %5
%23 = call i32 @free(i8* %22)
ret i32 0
}

LLVM IR (-O2):
@__const.main.name = [5 x i8] c"John\00"
@__const.main.color = [5 x i8] c"blue\00"
@.str = [34 x i8] c"P. Sherman 42 Wallaby Way, Sydney\00"
@.str.1 = [52 x i8] c"This is %s. He likes the color %s. He lives in %s.\0A\00"
@.str.2 = [26 x i8] c"%s is a %d letters name.\0A\00"
@.str.3 = [9 x i8] c"This is \00"
@.str.4 = [23 x i8] c"a concatenated string.\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [9 x i8] c"John Doe\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @length(i8* %3)
%7 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 %6)
%8 = call i8* @concatenate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%10 = call i8* @substring(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 5, i32 3)
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%12 = call i32 @free(i8* %10)
ret i32 0
}