#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 */
char EOF;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int *);
char fscanf(int /*<<< orphan*/ *, char *, int *);
char getc(int /*<<< orphan*/ *);
int *malloc(unsigned int);
int numzero(int *, unsigned int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int *realloc(int *, unsigned int);
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned i = 0, ibs = 32;
  int a;
  int *ib = malloc(ibs * sizeof(int));
  char c;
  if (argc != 2) {
    printf("Usage: %s [FILE]\n", argv[0]);
    return 1;
  }
  fp = fopen(*++argv, "r");
  while (fscanf(fp, "%d", &a) != EOF) {
    if (i == ibs) {
      ibs += ibs / 2;
      ib = realloc(ib, ibs * sizeof(int));
    }
    ib[i++] = a;
    if ((c = getc(fp)) == '\n' || c == EOF) {
      printf("%d\n", numzero(ib, i, 4, 0));
      i = 0;
    }
  }
  free(ib);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x20,-0x20(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e1 <main+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12df <main+0x15f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe17(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe05(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
movsbl %al,%eax
mov    0x2dc6(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12cf <main+0x14f>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    125b <main+0xdb>
mov    -0x20(%rbp),%eax
shr    $0x1,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
mov    %ecx,%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     12a0 <main+0x120>
movsbl -0x31(%rbp),%eax
mov    0x2d53(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12ca <main+0x14a>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1090 <numzero@plt>
mov    %eax,%esi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1204 <main+0x84>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x80,%edi
call   1060 <malloc@plt>
cmp    $0x2,%ebp
jne    11e2 <main+0x62>
mov    %rax,%r15
mov    0x8(%r14),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe58(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x2e18(%rip),%r13
cmp    0x0(%r13),%al
jne    1207 <main+0x87>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11f8 <main+0x78>
mov    (%r14),%rsi
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    $0x20,%r12d
lea    0xdfe(%rip),%rbx
jmp    125d <main+0xdd>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1090 <numzero@plt>
lea    0xddf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0x4(%rsp),%rdx
call   1050 <fscanf@plt>
cmp    0x0(%r13),%al
je     11d6 <main+0x56>
cmp    %r12d,%ebp
jne    128d <main+0x10d>
mov    %r15,%rdi
mov    %r14,%r15
mov    %r13,%r14
mov    %r12d,%r13d
shr    %r13d
add    %r12d,%r13d
lea    0x0(,%r13,4),%esi
call   1070 <realloc@plt>
mov    %r13d,%r12d
mov    %r14,%r13
mov    %r15,%r14
mov    %rax,%r15
mov    0x4(%rsp),%eax
mov    %ebp,%ecx
add    $0x1,%ebp
mov    %eax,(%r15,%rcx,4)
mov    %r14,%rdi
call   10a0 <getc@plt>
cmp    $0xa,%al
je     1220 <main+0xa0>
cmp    0x0(%r13),%al
jne    1243 <main+0xc3>
jmp    1220 <main+0xa0>

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

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i8 0
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @malloc(i32 128)
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %50
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call signext i8 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %47, label %17
17: ; preds = %10, %42
%18 = phi i32* [ %29, %42 ], [ %5, %10 ]
%19 = phi i32 [ %28, %42 ], [ 32, %10 ]
%20 = phi i32 [ %43, %42 ], [ 0, %10 ]
%21 = icmp eq i32 %20, %19
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = lshr i32 %19, 1
%24 = add i32 %23, %19
%25 = shl i32 %24, 2
%26 = call i32* @realloc(i32* %18, i32 %25)
br label %27
27: ; preds = %22, %17
%28 = phi i32 [ %24, %22 ], [ %19, %17 ]
%29 = phi i32* [ %26, %22 ], [ %18, %17 ]
%30 = load i32, i32* %3
%31 = add i32 %20, 1
%32 = zext i32 %20 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
store i32 %30, i32* %33
%34 = call signext i8 @getc(i32* %13)
%35 = icmp eq i8 %34, 10
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %34, %36
%38 = select i1 %35, i1 true, i1 %37
br i1 %38, label %39, label %42
39: ; preds = %27
%40 = call i32 @numzero(i32* %29, i32 %31, i32 4, i32 0)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %27, %39
%43 = phi i32 [ 0, %39 ], [ %31, %27 ]
%44 = call signext i8 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%45 = load i8, i8* @EOF
%46 = icmp eq i8 %44, %45
br i1 %46, label %47, label %17
47: ; preds = %42, %10
%48 = phi i32* [ %5, %10 ], [ %29, %42 ]
%49 = call i32 @free(i32* %48)
br label %50
50: ; preds = %47, %7
%51 = phi i32 [ 1, %7 ], [ 0, %47 ]
ret i32 %51
}