#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char const *);
char *get_line(int /*<<< orphan*/ *);
scalar_t__ string_null_or_empty(char *);
int chunk_concat(const char *new_name, const char *const *filenames,
                 int num_files, char *ln_prefix, char *fc_prefix) {
  FILE *old_file, *new_file;
  char *line;
  if (string_null_or_empty(ln_prefix) && string_null_or_empty(fc_prefix))
    return 0;
  new_file = fopen(new_name, "w");
  if (!new_file)
    return 0;
  if (!ln_prefix)
    ln_prefix = "";
  if (!fc_prefix)
    fc_prefix = "";
  int i;
  for (i = 0; i < num_files; ++i) {
    const char *current_file_name = filenames[i];
    old_file = fopen(current_file_name, "r");
    if (old_file == NULL)
      return 0;
    fprintf(new_file, "%s%s\n", ln_prefix, current_file_name);
    while ((line = get_line(old_file)) != NULL)
      fprintf(new_file, "%s%s", fc_prefix, line);
    fclose(old_file);
  }
  fclose(new_file);
  return 1;
}


x86 assembly (clang, -O0):
<chunk_concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <string_null_or_empty@plt>
cmp    $0x0,%rax
je     119d <chunk_concat+0x4d>
mov    -0x30(%rbp),%rdi
call   1060 <string_null_or_empty@plt>
cmp    $0x0,%rax
je     119d <chunk_concat+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    12b5 <chunk_concat+0x165>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11c8 <chunk_concat+0x78>
movl   $0x0,-0x4(%rbp)
jmp    12b5 <chunk_concat+0x165>
cmpq   $0x0,-0x28(%rbp)
jne    11de <chunk_concat+0x8e>
lea    0xe2f(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f4 <chunk_concat+0xa4>
lea    0xe19(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12a5 <chunk_concat+0x155>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1242 <chunk_concat+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    12b5 <chunk_concat+0x165>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x58(%rbp),%rcx
lea    0xdaf(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <get_line@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     128e <chunk_concat+0x13e>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xd86(%rip),%rsi
call   1050 <fprintf@plt>
jmp    125a <chunk_concat+0x10a>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11fb <chunk_concat+0xab>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chunk_concat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r12
mov    %edx,%r14d
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbx
mov    %rcx,%rbp
mov    %rcx,%rdi
call   1060 <string_null_or_empty@plt>
test   %rax,%rax
je     118f <chunk_concat+0x3f>
mov    %r12,%rdi
call   1060 <string_null_or_empty@plt>
xor    %ecx,%ecx
test   %rax,%rax
jne    1261 <chunk_concat+0x111>
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1250 <chunk_concat+0x100>
mov    %rax,%rbx
test   %rbp,%rbp
lea    0xe55(%rip),%rax
cmove  %rax,%rbp
mov    %rbp,0x8(%rsp)
test   %r12,%r12
cmove  %rax,%r12
test   %r14d,%r14d
jle    1254 <chunk_concat+0x104>
mov    %r14d,%eax
mov    %rax,(%rsp)
lea    0xe2f(%rip),%r13
xor    %r14d,%r14d
jmp    11f2 <chunk_concat+0xa2>
mov    %rbp,%rdi
call   1040 <fclose@plt>
add    $0x1,%r14
cmp    (%rsp),%r14
je     1254 <chunk_concat+0x104>
mov    0x10(%rsp),%rax
mov    (%rax,%r14,8),%r15
mov    %r15,%rdi
lea    0xdfd(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1250 <chunk_concat+0x100>
mov    %rax,%rbp
mov    %rbx,%rdi
lea    0xde8(%rip),%rsi
mov    0x8(%rsp),%rdx
mov    %r15,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11e0 <chunk_concat+0x90>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rax,%rcx
jmp    1230 <chunk_concat+0xe0>
xor    %ecx,%ecx
jmp    1261 <chunk_concat+0x111>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%s%s\0A\00"
@.str.4 = [5 x i8] c"%s%s\00"
define i32 @chunk_concat(i8* %0, i8** %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i8*
store i8* %0, i8** %7
store i8** %1, i8*** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%17 = load i8*, i8** %10
%18 = call i64 @string_null_or_empty(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %5
%21 = load i8*, i8** %11
%22 = call i64 @string_null_or_empty(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %6
br label %78
25: ; preds = %20, %5
%26 = load i8*, i8** %7
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %13
%28 = load i32*, i32** %13
%29 = icmp ne i32* %28, null
br i1 %29, label %31, label %30
30: ; preds = %25
store i32 0, i32* %6
br label %78
31: ; preds = %25
%32 = load i8*, i8** %10
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %31
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %35
35: ; preds = %34, %31
%36 = load i8*, i8** %11
%37 = icmp ne i8* %36, null
br i1 %37, label %39, label %38
38: ; preds = %35
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %39
39: ; preds = %38, %35
store i32 0, i32* %15
br label %40
40: ; preds = %72, %39
%41 = load i32, i32* %15
%42 = load i32, i32* %9
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %75
44: ; preds = %40
%45 = load i8**, i8*** %8
%46 = load i32, i32* %15
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
store i8* %49, i8** %16
%50 = load i8*, i8** %16
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %51, i32** %12
%52 = load i32*, i32** %12
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %55
54: ; preds = %44
store i32 0, i32* %6
br label %78
55: ; preds = %44
%56 = load i32*, i32** %13
%57 = load i8*, i8** %10
%58 = load i8*, i8** %16
%59 = call i32 @fprintf(i32* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %57, i8* %58)
br label %60
60: ; preds = %64, %55
%61 = load i32*, i32** %12
%62 = call i8* @get_line(i32* %61)
store i8* %62, i8** %14
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = load i32*, i32** %13
%66 = load i8*, i8** %11
%67 = load i8*, i8** %14
%68 = call i32 @fprintf(i32* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %66, i8* %67)
br label %60
69: ; preds = %60
%70 = load i32*, i32** %12
%71 = call i32 @fclose(i32* %70)
br label %72
72: ; preds = %69
%73 = load i32, i32* %15
%74 = add nsw i32 %73, 1
store i32 %74, i32* %15
br label %40
75: ; preds = %40
%76 = load i32*, i32** %13
%77 = call i32 @fclose(i32* %76)
store i32 1, i32* %6
br label %78
78: ; preds = %75, %54, %30, %24
%79 = load i32, i32* %6
ret i32 %79
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%s%s\0A\00"
@.str.4 = [5 x i8] c"%s%s\00"
define i32 @chunk_concat(i8* nocapture %0, i8** nocapture %1, i32 %2, i8* %3, i8* %4) {
%6 = tail call i64 @string_null_or_empty(i8* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i64 @string_null_or_empty(i8* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %43
11: ; preds = %8, %5
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %43, label %14
14: ; preds = %11
%15 = icmp eq i8* %3, null
%16 = select i1 %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %3
%17 = icmp eq i8* %4, null
%18 = select i1 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %4
%19 = icmp sgt i32 %2, 0
br i1 %19, label %20, label %41
20: ; preds = %14
%21 = zext i32 %2 to i64
br label %22
22: ; preds = %20, %37
%23 = phi i64 [ 0, %20 ], [ %39, %37 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %43, label %28
28: ; preds = %22
%29 = tail call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %16, i8* %25)
%30 = tail call i8* @get_line(i32* %26)
%31 = icmp eq i8* %30, null
br i1 %31, label %37, label %32
32: ; preds = %28, %32
%33 = phi i8* [ %35, %32 ], [ %30, %28 ]
%34 = tail call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8* %33)
%35 = tail call i8* @get_line(i32* %26)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %32
37: ; preds = %32, %28
%38 = tail call i32 @fclose(i32* %26)
%39 = add nuw nsw i64 %23, 1
%40 = icmp eq i64 %39, %21
br i1 %40, label %41, label %22
41: ; preds = %37, %14
%42 = tail call i32 @fclose(i32* %12)
br label %43
43: ; preds = %22, %41, %11, %8
%44 = phi i32 [ 0, %8 ], [ 0, %11 ], [ 1, %41 ], [ 0, %22 ]
ret i32 %44
}