#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*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stderr;
int strlen(char *);
int cbind(const int nfiles, char **filenames_in, const char *filename_out,
          const int n, const int p, const char sep) {
  int i, j, p2 = 2 * p, p22 = p2 + 2;
  FILE **in = NULL, *out = NULL;
  char *buf = NULL;
  if (!(in = malloc(sizeof(FILE) * nfiles))) {
    fprintf(stderr, "can't malloc %ld bytes\n", (long)sizeof(FILE) * nfiles);
    return 0;
  };
  if (!(buf = malloc(sizeof(char) * p22))) {
    fprintf(stderr, "can't malloc %ld bytes\n", (long)sizeof(char) * p22);
    return 0;
  };
  if (!(out = fopen(filename_out, "wt"))) {
    fprintf(stderr, "can't open file %s\n", filename_out);
    return 0;
  };
  for (j = 0; j < nfiles; j++)
    if (!(in[j] = fopen(filenames_in[j], "rt"))) {
      fprintf(stderr, "can't open file %s\n", filenames_in[j]);
      return 0;
    };
  for (i = 0; i < n; i++) {
    printf("%d of %d", i, n);
    for (j = 0; j < nfiles; j++) {
      if (!(buf = fgets(buf, p22, in[j]))) {
        fprintf(stderr, "error reading from input file");
        return 0;
      }
      buf[strlen(buf) - 1] = '\0';
      fprintf(out, "%s", buf);
      if (sep != '\0' && j < nfiles - 1)
        fprintf(out, "%c", sep);
    }
    fprintf(out, "\n");
    printf("\r");
  }
  for (j = 0; j < nfiles; j++)
    fclose(in[j]);
  free(in);
  fclose(out);
  free(buf);
  return 1;
}


x86 assembly (clang, -O0):
<cbind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %r9b,%al
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1213 <cbind+0x93>
mov    0x2df2(%rip),%rax
mov    (%rax),%rdi
movslq -0x8(%rbp),%rdx
shl    $0x2,%rdx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14aa <cbind+0x32a>
movslq -0x34(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    125c <cbind+0xdc>
mov    0x2da9(%rip),%rax
mov    (%rax),%rdi
movslq -0x34(%rbp),%rdx
shl    $0x0,%rdx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14aa <cbind+0x32a>
mov    -0x18(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    12a2 <cbind+0x122>
mov    0x2d5f(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14aa <cbind+0x32a>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1326 <cbind+0x1a6>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd67(%rip),%rsi
call   10a0 <fopen@plt>
mov    -0x40(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1313 <cbind+0x193>
mov    0x2cf6(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd1b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14aa <cbind+0x32a>
jmp    1318 <cbind+0x198>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a9 <cbind+0x129>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1456 <cbind+0x2d6>
mov    -0x28(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1428 <cbind+0x2a8>
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   1070 <fgets@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    13aa <cbind+0x22a>
mov    0x2c53(%rip),%rax
mov    (%rax),%rdi
lea    0xca4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14aa <cbind+0x32a>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rdx
lea    0xc7f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
je     1415 <cbind+0x295>
mov    -0x2c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1415 <cbind+0x295>
mov    -0x48(%rbp),%rdi
movsbl -0x21(%rbp),%edx
lea    0xc4e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    141a <cbind+0x29a>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1354 <cbind+0x1d4>
mov    -0x48(%rbp),%rdi
lea    0xbfa(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xc1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    132d <cbind+0x1ad>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1488 <cbind+0x308>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    145d <cbind+0x2dd>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbind>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,0x24(%rsp)
mov    %r8d,%r15d
mov    %ecx,0xc(%rsp)
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebp
movslq %edi,%rbx
shl    $0x2,%rbx
mov    %ebx,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     12a2 <cbind+0xe2>
mov    %rax,%r14
add    %r15d,%r15d
add    $0x2,%r15d
mov    %r15d,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     12bd <cbind+0xfd>
mov    %rax,%rbx
lea    0xdfa(%rip),%rsi
mov    %r12,%rdi
call   10d0 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1389 <cbind+0x1c9>
mov    %r15d,0x2c(%rsp)
mov    %rbp,0x18(%rsp)
test   %ebp,%ebp
jle    1273 <cbind+0xb3>
mov    0x18(%rsp),%r15d
xor    %ebp,%ebp
lea    0xddf(%rip),%r12
mov    0x0(%r13,%rbp,8),%rdi
mov    %r12,%rsi
call   10d0 <fopen@plt>
mov    %rax,(%r14,%rbp,8)
test   %rax,%rax
je     13c5 <cbind+0x205>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1250 <cbind+0x90>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    13f5 <cbind+0x235>
mov    0x18(%rsp),%r15
lea    -0x1(%r15),%eax
mov    0x24(%rsp),%ebp
movsbl %bpl,%ecx
mov    %ecx,0x28(%rsp)
cltq
mov    %rax,0x30(%rsp)
mov    %r15d,%r12d
xor    %esi,%esi
jmp    130c <cbind+0x14c>
mov    0x2d37(%rip),%rax
mov    (%rax),%rdi
lea    0xd4d(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
jmp    13dd <cbind+0x21d>
movslq %r15d,%rdx
mov    0x2d19(%rip),%rax
mov    (%rax),%rdi
lea    0xd2f(%rip),%rsi
jmp    13db <cbind+0x21b>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    0x10(%rsp),%rsi
call   1090 <fputc@plt>
mov    $0xd,%edi
call   1040 <putchar@plt>
mov    0x20(%rsp),%esi
add    $0x1,%esi
mov    0xc(%rsp),%edx
cmp    %edx,%esi
je     13fa <cbind+0x23a>
lea    0xd1f(%rip),%rdi
mov    %esi,0x20(%rsp)
xor    %eax,%eax
call   1070 <printf@plt>
test   %r15d,%r15d
jle    12e0 <cbind+0x120>
xor    %r13d,%r13d
jmp    1339 <cbind+0x179>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r13,%r12
je     12e0 <cbind+0x120>
mov    (%r14,%r13,8),%rdx
mov    %rbx,%rdi
mov    0x2c(%rsp),%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     13a1 <cbind+0x1e1>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
call   1080 <fputs@plt>
test   %bpl,%bpl
je     1330 <cbind+0x170>
cmp    0x30(%rsp),%r13
jge    1330 <cbind+0x170>
mov    0x28(%rsp),%edi
mov    0x10(%rsp),%rsi
call   1090 <fputc@plt>
jmp    1330 <cbind+0x170>
mov    0x2c50(%rip),%rax
mov    (%rax),%rdi
lea    0xc81(%rip),%rsi
xor    %ebp,%ebp
mov    %r12,%rdx
jmp    13dd <cbind+0x21d>
mov    0x2c38(%rip),%rax
mov    (%rax),%rcx
lea    0xc89(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
xor    %ebp,%ebp
jmp    13e4 <cbind+0x224>
mov    0x2c14(%rip),%rax
mov    (%rax),%rdi
mov    0x0(%r13,%rbp,8),%rdx
lea    0xc40(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x18(%rsp),%r15
test   %r15d,%r15d
jle    1422 <cbind+0x262>
mov    %r15d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbp,8),%rdi
call   1050 <fclose@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1410 <cbind+0x250>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
jmp    13e4 <cbind+0x224>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [24 x i8] c"can't malloc %ld bytes\0A\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [20 x i8] c"can't open file %s\0A\00"
@.str.3 = [3 x i8] c"rt\00"
@.str.4 = [9 x i8] c"%d of %d\00"
@.str.5 = [30 x i8] c"error reading from input file\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [3 x i8] c"%c\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [2 x i8] c"\0D\00"
define i32 @cbind(i32 %0, i8** %1, i8* %2, i32 %3, i32 %4, i8 signext %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32**
%19 = alloca i32*
%20 = alloca i8*
store i32 %0, i32* %8
store i8** %1, i8*** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8 %5, i8* %13
%21 = load i32, i32* %12
%22 = mul nsw i32 2, %21
store i32 %22, i32* %16
%23 = load i32, i32* %16
%24 = add nsw i32 %23, 2
store i32 %24, i32* %17
store i32** null, i32*** %18
store i32* null, i32** %19
store i8* null, i8** %20
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = mul i64 4, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
%30 = bitcast i8* %29 to i32**
store i32** %30, i32*** %18
%31 = icmp ne i32** %30, null
br i1 %31, label %38, label %32
32: ; preds = %6
%33 = load i32*, i32** @stderr
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = mul nsw i64 4, %35
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %36)
store i32 0, i32* %7
br label %171
38: ; preds = %6
%39 = load i32, i32* %17
%40 = sext i32 %39 to i64
%41 = mul i64 1, %40
%42 = trunc i64 %41 to i32
%43 = call i8* @malloc(i32 %42)
store i8* %43, i8** %20
%44 = icmp ne i8* %43, null
br i1 %44, label %51, label %45
45: ; preds = %38
%46 = load i32*, i32** @stderr
%47 = load i32, i32* %17
%48 = sext i32 %47 to i64
%49 = mul nsw i64 1, %48
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %49)
store i32 0, i32* %7
br label %171
51: ; preds = %38
%52 = load i8*, i8** %10
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %53, i32** %19
%54 = icmp ne i32* %53, null
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = load i32*, i32** @stderr
%57 = load i8*, i8** %10
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %57)
store i32 0, i32* %7
br label %171
59: ; preds = %51
store i32 0, i32* %15
br label %60
60: ; preds = %85, %59
%61 = load i32, i32* %15
%62 = load i32, i32* %8
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %88
64: ; preds = %60
%65 = load i8**, i8*** %9
%66 = load i32, i32* %15
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%71 = load i32**, i32*** %18
%72 = load i32, i32* %15
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32*, i32** %71, i64 %73
store i32* %70, i32** %74
%75 = icmp ne i32* %70, null
br i1 %75, label %84, label %76
76: ; preds = %64
%77 = load i32*, i32** @stderr
%78 = load i8**, i8*** %9
%79 = load i32, i32* %15
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %78, i64 %80
%82 = load i8*, i8** %81
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %82)
store i32 0, i32* %7
br label %171
84: ; preds = %64
br label %85
85: ; preds = %84
%86 = load i32, i32* %15
%87 = add nsw i32 %86, 1
store i32 %87, i32* %15
br label %60
88: ; preds = %60
store i32 0, i32* %14
br label %89
89: ; preds = %145, %88
%90 = load i32, i32* %14
%91 = load i32, i32* %11
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %148
93: ; preds = %89
%94 = load i32, i32* %14
%95 = load i32, i32* %11
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %94, i32 %95)
store i32 0, i32* %15
br label %97
97: ; preds = %138, %93
%98 = load i32, i32* %15
%99 = load i32, i32* %8
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %141
101: ; preds = %97
%102 = load i8*, i8** %20
%103 = load i32, i32* %17
%104 = load i32**, i32*** %18
%105 = load i32, i32* %15
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32*, i32** %104, i64 %106
%108 = load i32*, i32** %107
%109 = call i8* @fgets(i8* %102, i32 %103, i32* %108)
store i8* %109, i8** %20
%110 = icmp ne i8* %109, null
br i1 %110, label %114, label %111
111: ; preds = %101
%112 = load i32*, i32** @stderr
%113 = call i32 (i32*, i8*, ...) @fprintf(i32* %112, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %7
br label %171
114: ; preds = %101
%115 = load i8*, i8** %20
%116 = load i8*, i8** %20
%117 = call i32 @strlen(i8* %116)
%118 = sub nsw i32 %117, 1
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8, i8* %115, i64 %119
store i8 0, i8* %120
%121 = load i32*, i32** %19
%122 = load i8*, i8** %20
%123 = call i32 (i32*, i8*, ...) @fprintf(i32* %121, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %122)
%124 = load i8, i8* %13
%125 = sext i8 %124 to i32
%126 = icmp ne i32 %125, 0
br i1 %126, label %127, label %137
127: ; preds = %114
%128 = load i32, i32* %15
%129 = load i32, i32* %8
%130 = sub nsw i32 %129, 1
%131 = icmp slt i32 %128, %130
br i1 %131, label %132, label %137
132: ; preds = %127
%133 = load i32*, i32** %19
%134 = load i8, i8* %13
%135 = sext i8 %134 to i32
%136 = call i32 (i32*, i8*, ...) @fprintf(i32* %133, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %135)
br label %137
137: ; preds = %132, %127, %114
br label %138
138: ; preds = %137
%139 = load i32, i32* %15
%140 = add nsw i32 %139, 1
store i32 %140, i32* %15
br label %97
141: ; preds = %97
%142 = load i32*, i32** %19
%143 = call i32 (i32*, i8*, ...) @fprintf(i32* %142, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %145
145: ; preds = %141
%146 = load i32, i32* %14
%147 = add nsw i32 %146, 1
store i32 %147, i32* %14
br label %89
148: ; preds = %89
store i32 0, i32* %15
br label %149
149: ; preds = %160, %148
%150 = load i32, i32* %15
%151 = load i32, i32* %8
%152 = icmp slt i32 %150, %151
br i1 %152, label %153, label %163
153: ; preds = %149
%154 = load i32**, i32*** %18
%155 = load i32, i32* %15
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i32*, i32** %154, i64 %156
%158 = load i32*, i32** %157
%159 = call i32 @fclose(i32* %158)
br label %160
160: ; preds = %153
%161 = load i32, i32* %15
%162 = add nsw i32 %161, 1
store i32 %162, i32* %15
br label %149
163: ; preds = %149
%164 = load i32**, i32*** %18
%165 = bitcast i32** %164 to i8*
%166 = call i32 @free(i8* %165)
%167 = load i32*, i32** %19
%168 = call i32 @fclose(i32* %167)
%169 = load i8*, i8** %20
%170 = call i32 @free(i8* %169)
store i32 1, i32* %7
br label %171
171: ; preds = %163, %111, %76, %55, %45, %32
%172 = load i32, i32* %7
ret i32 %172
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [24 x i8] c"can't malloc %ld bytes\0A\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [20 x i8] c"can't open file %s\0A\00"
@.str.3 = [3 x i8] c"rt\00"
@.str.4 = [9 x i8] c"%d of %d\00"
@.str.5 = [30 x i8] c"error reading from input file\00"
define i32 @cbind(i32 %0, i8** nocapture %1, i8* %2, i32 %3, i32 %4, i8 signext %5) {
%7 = shl nsw i32 %4, 1
%8 = add nsw i32 %7, 2
%9 = sext i32 %0 to i64
%10 = shl nsw i64 %9, 2
%11 = trunc i64 %10 to i32
%12 = tail call i8* @malloc(i32 %11)
%13 = bitcast i8* %12 to i32**
%14 = icmp eq i8* %12, null
br i1 %14, label %15, label %18
15: ; preds = %6
%16 = load i32*, i32** @stderr
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %107
18: ; preds = %6
%19 = tail call i8* @malloc(i32 %8)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = sext i32 %8 to i64
%23 = load i32*, i32** @stderr
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %22)
br label %107
25: ; preds = %18
%26 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = icmp sgt i32 %0, 0
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = zext i32 %0 to i64
br label %43
32: ; preds = %25
%33 = load i32*, i32** @stderr
%34 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %107
35: ; preds = %56, %28
%36 = icmp sgt i32 %3, 0
br i1 %36, label %37, label %59
37: ; preds = %35
%38 = icmp ne i8 %5, 0
%39 = add nsw i32 %0, -1
%40 = sext i8 %5 to i32
%41 = sext i32 %39 to i64
%42 = zext i32 %0 to i64
br label %63
43: ; preds = %30, %56
%44 = phi i64 [ 0, %30 ], [ %57, %56 ]
%45 = getelementptr inbounds i8*, i8** %1, i64 %44
%46 = load i8*, i8** %45
%47 = tail call i32* @fopen(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%48 = getelementptr inbounds i32*, i32** %13, i64 %44
store i32* %47, i32** %48
%49 = icmp eq i32* %47, null
br i1 %49, label %50, label %56
50: ; preds = %43
%51 = and i64 %44, 4294967295
%52 = getelementptr inbounds i8*, i8** %1, i64 %51
%53 = load i32*, i32** @stderr
%54 = load i8*, i8** %52
%55 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %54)
br label %107
56: ; preds = %43
%57 = add nuw nsw i64 %44, 1
%58 = icmp eq i64 %57, %31
br i1 %58, label %35, label %43
59: ; preds = %90, %35
%60 = phi i8* [ %19, %35 ], [ %91, %90 ]
br i1 %29, label %61, label %103
61: ; preds = %59
%62 = zext i32 %0 to i64
br label %96
63: ; preds = %37, %90
%64 = phi i8* [ %19, %37 ], [ %91, %90 ]
%65 = phi i32 [ 0, %37 ], [ %94, %90 ]
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %65, i32 %3)
br i1 %29, label %67, label %90
67: ; preds = %63, %87
%68 = phi i64 [ %88, %87 ], [ 0, %63 ]
%69 = phi i8* [ %72, %87 ], [ %64, %63 ]
%70 = getelementptr inbounds i32*, i32** %13, i64 %68
%71 = load i32*, i32** %70
%72 = tail call i8* @fgets(i8* %69, i32 %8, i32* %71)
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %77
74: ; preds = %67
%75 = load i32*, i32** @stderr
%76 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 29, i64 1, i32* %75)
br label %107
77: ; preds = %67
%78 = tail call i32 @strlen(i8* %72)
%79 = add nsw i32 %78, -1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %72, i64 %80
store i8 0, i8* %81
%82 = tail call i32 @fputs(i8* %72, i32* %26)
%83 = icmp slt i64 %68, %41
%84 = select i1 %38, i1 %83, i1 false
br i1 %84, label %85, label %87
85: ; preds = %77
%86 = tail call i32 @fputc(i32 %40, i32* %26)
br label %87
87: ; preds = %77, %85
%88 = add nuw nsw i64 %68, 1
%89 = icmp eq i64 %88, %42
br i1 %89, label %90, label %67
90: ; preds = %87, %63
%91 = phi i8* [ %64, %63 ], [ %72, %87 ]
%92 = tail call i32 @fputc(i32 10, i32* %26)
%93 = tail call i32 @putchar(i32 13)
%94 = add nuw nsw i32 %65, 1
%95 = icmp eq i32 %94, %3
br i1 %95, label %59, label %63
96: ; preds = %61, %96
%97 = phi i64 [ 0, %61 ], [ %101, %96 ]
%98 = getelementptr inbounds i32*, i32** %13, i64 %97
%99 = load i32*, i32** %98
%100 = tail call i32 @fclose(i32* %99)
%101 = add nuw nsw i64 %97, 1
%102 = icmp eq i64 %101, %62
br i1 %102, label %103, label %96
103: ; preds = %96, %59
%104 = tail call i32 @free(i8* %12)
%105 = tail call i32 @fclose(i32* %26)
%106 = tail call i32 @free(i8* %60)
br label %107
107: ; preds = %103, %74, %50, %32, %21, %15
%108 = phi i32 [ 0, %50 ], [ 0, %74 ], [ 1, %103 ], [ 0, %32 ], [ 0, %21 ], [ 0, %15 ]
ret i32 %108
}