#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 *mystrcat(char *, char *);
int /*<<< orphan*/ mystrcpy(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void test3() {
  char a[200];
  char *b;
  mystrcpy(a, "Hello world");
  b = mystrcat(a, ", CS240 C Programming");
  b = mystrcat(a, ", This is a great course");
  printf("\"%s\"\n", a);
  printf("\"%s\"\n", b);
  mystrcpy(a, "");
  b = mystrcat(a, "");
  b = mystrcat(b, "Hello");
  printf("\"%s\"\n", a);
  printf("\"%s\"\n", b);
}


x86 assembly (clang, -O0):
<test3>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
lea    -0xd0(%rbp),%rdi
lea    0xeb7(%rip),%rsi
call   1050 <mystrcpy@plt>
lea    -0xd0(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1040 <mystrcat@plt>
mov    %rax,-0xd8(%rbp)
lea    -0xd0(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1040 <mystrcat@plt>
mov    %rax,-0xd8(%rbp)
lea    -0xd0(%rbp),%rsi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    -0xd8(%rbp),%rsi
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
lea    -0xd0(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <mystrcpy@plt>
lea    -0xd0(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1040 <mystrcat@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <mystrcat@plt>
mov    %rax,-0xd8(%rbp)
lea    -0xd0(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
mov    -0xd8(%rbp),%rsi
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test3>:
push   %r15
push   %r14
push   %rbx
sub    $0xd0,%rsp
lea    0xebd(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <mystrcpy@plt>
lea    0xeb7(%rip),%rsi
mov    %r15,%rdi
call   1040 <mystrcat@plt>
lea    0xebe(%rip),%rsi
mov    %r15,%rdi
call   1040 <mystrcat@plt>
mov    %rax,%rbx
lea    0xec5(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xead(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <mystrcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <mystrcat@plt>
lea    0xe91(%rip),%rsi
mov    %rax,%rdi
call   1040 <mystrcat@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [22 x i8] c", CS240 C Programming\00"
@.str.2 = [25 x i8] c", This is a great course\00"
@.str.3 = [6 x i8] c"\22%s\22\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [6 x i8] c"Hello\00"
define void @test3() {
%1 = alloca [200 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%4 = call i32 @mystrcpy(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%6 = call i8* @mystrcat(i8* %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i8* %6, i8** %2
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%8 = call i8* @mystrcat(i8* %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i8* %8, i8** %2
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%10 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %2
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%14 = call i32 @mystrcpy(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%16 = call i8* @mystrcat(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = call i8* @mystrcat(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i8* %18, i8** %2
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %2
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %21)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [22 x i8] c", CS240 C Programming\00"
@.str.2 = [25 x i8] c", This is a great course\00"
@.str.3 = [6 x i8] c"\22%s\22\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [6 x i8] c"Hello\00"
define void @test3() {
%1 = alloca [200 x i8]
%2 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%3 = call i32 @mystrcpy(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = call i8* @mystrcat(i8* %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%5 = call i8* @mystrcat(i8* %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%7 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%8 = call i32 @mystrcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%9 = call i8* @mystrcat(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%10 = call i8* @mystrcat(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %10)
ret void
}