#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 /*<<< orphan*/ abort();
int /*<<< orphan*/ printf(char *, char *);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char arr[100];
  strcpy(arr, "hello world!");
  int start = strlen(arr);
  char *result = strcat(arr, " appended string");
  if (result != arr) {
    abort();
  }
  printf("%s\n", result);
  result = strcat(arr, " again appended!");
  if (result != arr) {
    abort();
  }
  printf("%s\n", result);
  result = strcat(arr, "");
  if (result != arr) {
    abort();
  }
  printf("%s\n", result);
  result = strcat(arr, "a");
  if (result != arr) {
    abort();
  }
  printf("%s\n", result);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x70(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
je     11a3 <main+0x53>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x80(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1060 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
je     11df <main+0x8f>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x80(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1060 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
je     121b <main+0xcb>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x80(%rbp),%rsi
lea    0xdf8(%rip),%rdi
call   1060 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
je     1257 <main+0x107>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x80(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xec2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movups 0xead(%rip),%xmm0
movups %xmm0,(%rsp,%rax,1)
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xeae(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movups 0xe98(%rip),%xmm0
movups %xmm0,(%rsp,%rax,1)
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x61,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"hello world!\00"
@.str.1 = [17 x i8] c" appended string\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [17 x i8] c" again appended!\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [2 x i8] c"a\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = alloca i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %2
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%9 = call i8* @strcat(i8* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%12 = icmp ne i8* %10, %11
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %0
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%19 = call i8* @strcat(i8* %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%22 = icmp ne i8* %20, %21
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %15
%26 = load i8*, i8** %3
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%29 = call i8* @strcat(i8* %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
store i8* %29, i8** %3
%30 = load i8*, i8** %3
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%32 = icmp ne i8* %30, %31
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %25
%36 = load i8*, i8** %3
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%39 = call i8* @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %39, i8** %3
%40 = load i8*, i8** %3
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%42 = icmp ne i8* %40, %41
br i1 %42, label %43, label %45
43: ; preds = %35
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %35
%46 = load i8*, i8** %3
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"hello world!\00"
@.str.1 = [17 x i8] c" appended string\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [17 x i8] c" again appended!\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strlen(i8* %2)
%5 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %2)
%6 = getelementptr [100 x i8], [100 x i8]* %1, i64 0, i64 %5
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%8 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %2)
%9 = getelementptr [100 x i8], [100 x i8]* %1, i64 0, i64 %8
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%12 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %2)
%13 = getelementptr [100 x i8], [100 x i8]* %1, i64 0, i64 %12
%14 = bitcast i8* %13 to i16*
store i16 97, i16* %14
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret i32 0
}