#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*/ chunk_concat(char *, char **, int, char *,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char **files = malloc(2 * sizeof(*files));
  files[0] = malloc(8 * sizeof(*files[0]));
  strcpy(files[0], "chunk.c");
  files[1] = malloc(8 * sizeof(*files[0]));
  strcpy(files[1], "chunk.h");
  if (!chunk_concat("large_chunk.txt", (char **)files, 2, "> ", NULL)) {
    fprintf(stderr, "chunk_test: chunk_concat failed\n");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x2,%edx
lea    0xe45(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <chunk_concat@plt>
cmp    $0x0,%eax
jne    120d <main+0xbd>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rbx)
lea    0xe79(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe72(%rip),%rdi
lea    0xe7b(%rip),%rcx
mov    %rbx,%rsi
mov    $0x2,%edx
xor    %r8d,%r8d
call   1060 <chunk_concat@plt>
test   %eax,%eax
je     11bd <main+0x6d>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"chunk.c\00"
@.str.1 = [8 x i8] c"chunk.h\00"
@.str.2 = [16 x i8] c"large_chunk.txt\00"
@.str.3 = [3 x i8] c"> \00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"chunk_test: chunk_concat failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i8* @malloc(i32 16)
%8 = bitcast i8* %7 to i8**
store i8** %8, i8*** %6
%9 = call i8* @malloc(i32 8)
%10 = load i8**, i8*** %6
%11 = getelementptr inbounds i8*, i8** %10, i64 0
store i8* %9, i8** %11
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%16 = call i8* @malloc(i32 8)
%17 = load i8**, i8*** %6
%18 = getelementptr inbounds i8*, i8** %17, i64 1
store i8* %16, i8** %18
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8**, i8*** %6
%24 = call i32 @chunk_concat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8** %23, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* null)
%25 = icmp ne i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"chunk.c\00"
@.str.1 = [8 x i8] c"chunk.h\00"
@.str.2 = [16 x i8] c"large_chunk.txt\00"
@.str.3 = [3 x i8] c"> \00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"chunk_test: chunk_concat failed\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%4 = bitcast i8* %3 to i8**
%5 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
store i8* %5, i8** %4
%6 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%8 = getelementptr inbounds i8*, i8** %4, i64 1
store i8* %7, i8** %8
%9 = tail call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @chunk_concat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8** %4, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* null)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
ret i32 0
}