#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 *catstr(char *, char *);
char *chomp(char *);
char *dupstr(char *);
char *firstword(char *);
char *pop(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char *argv[]) {
  char *s1 = "string one";
  char *s2 = "string two";
  char *dup = dupstr(s1);
  printf("'%s' with address %p was duplicated to '%s' with address %p\n", s1,
         &s1, dup, &dup);
  char *sc = catstr(s1, s2);
  printf("'%s' and '%s' were concatenated to '%s'\n", s1, s2, sc);
  char *s3 = "string three\n";
  printf("This string with a new line: %s\n", s3);
  s3 = chomp(s3);
  printf("Was chomped to remove the new line: %s\n", s3);
  s3 = pop(s3);
  printf("And now there is no s: %s\n", s3);
  printf("For string '%s'\n", s1);
  char *fw = firstword(s1);
  printf("The first word is '%s'\n", fw);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <dupstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe75(%rip),%rdi
lea    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%r8
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <catstr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9a(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <chomp@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1060 <pop@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <firstword@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rbx
mov    %rbx,(%rsp)
mov    %rbx,%rdi
call   1080 <dupstr@plt>
mov    %rax,0x8(%rsp)
lea    0xe92(%rip),%rdi
mov    %rsp,%rdx
lea    0x8(%rsp),%r8
mov    %rbx,%rsi
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rdi
lea    0xe67(%rip),%rbx
mov    %rbx,%rsi
call   1030 <catstr@plt>
mov    (%rsp),%rsi
lea    0xe9c(%rip),%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
lea    0xeaa(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <chomp@plt>
mov    %rax,%rbx
lea    0xebd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <pop@plt>
lea    0xecc(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rsi
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rdi
call   1050 <firstword@plt>
lea    0xecc(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"string one\00"
@.str.1 = [11 x i8] c"string two\00"
@.str.2 = [61 x i8] c"'%s' with address %p was duplicated to '%s' with address %p\0A\00"
@.str.3 = [41 x i8] c"'%s' and '%s' were concatenated to '%s'\0A\00"
@.str.4 = [14 x i8] c"string three\0A\00"
@.str.5 = [33 x i8] c"This string with a new line: %s\0A\00"
@.str.6 = [40 x i8] c"Was chomped to remove the new line: %s\0A\00"
@.str.7 = [27 x i8] c"And now there is no s: %s\0A\00"
@.str.8 = [17 x i8] c"For string '%s'\0A\00"
@.str.9 = [24 x i8] c"The first word is '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %6
%11 = load i8*, i8** %5
%12 = call i8* @dupstr(i8* %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %5
%14 = load i8*, i8** %7
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8** %5, i8* %14, i8** %7)
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i8* @catstr(i8* %16, i8* %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = load i8*, i8** %8
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %20, i8* %21)
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %9
%23 = load i8*, i8** %9
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %9
%26 = call i8* @chomp(i8* %25)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %9
%30 = call i8* @pop(i8* %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %5
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %5
%36 = call i8* @firstword(i8* %35)
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"string one\00"
@.str.1 = [11 x i8] c"string two\00"
@.str.2 = [61 x i8] c"'%s' with address %p was duplicated to '%s' with address %p\0A\00"
@.str.3 = [41 x i8] c"'%s' and '%s' were concatenated to '%s'\0A\00"
@.str.4 = [14 x i8] c"string three\0A\00"
@.str.5 = [33 x i8] c"This string with a new line: %s\0A\00"
@.str.6 = [40 x i8] c"Was chomped to remove the new line: %s\0A\00"
@.str.7 = [27 x i8] c"And now there is no s: %s\0A\00"
@.str.8 = [17 x i8] c"For string '%s'\0A\00"
@.str.9 = [24 x i8] c"The first word is '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = bitcast i8** %4 to i8*
%7 = tail call i8* @dupstr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3, i8* %7, i8** %4)
%9 = load i8*, i8** %3
%10 = call i8* @catstr(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%14 = call i8* @chomp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %14)
%16 = call i8* @pop(i8* %14)
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %3
%21 = call i8* @firstword(i8* %20)
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %21)
ret i32 0
}