#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 *, char *);
int hhistogram(int /*<<< orphan*/ *, int *, int, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int vhistogram(int /*<<< orphan*/ *, int *, int, int, int);
int wlength(int /*<<< orphan*/ *, int *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Missing input files!\n");
    return 1;
  }
  int i;
  FILE *in, *out;
  int a[1000];
  int size;
  int start, end;
  int rc1, rc2;
  for (i = 1; i < argc; i++) {
    in = fopen(argv[i], "r");
    if (in == NULL) {
      perror(argv[i]);
      continue;
    }
    out = fopen("output.dat", "w");
    size = wlength(in, a);
    start = 0;
    end = 0;
    rc1 = hhistogram(out, a, size, start, end);
    rc2 = vhistogram(out, a, size, start, end);
    if (rc1 != 0 || rc2 != 0) {
      printf("Error Occured!\n");
      return 1;
    }
    fclose(in);
    fclose(out);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xff0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ab <main+0x3b>
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e7 <main+0x177>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e0 <main+0x170>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe45(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fb <main+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <perror@plt>
jmp    12d2 <main+0x162>
lea    0xe16(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0xfd0(%rbp),%rsi
call   1050 <wlength@plt>
mov    %eax,-0xfd4(%rbp)
movl   $0x0,-0xfd8(%rbp)
movl   $0x0,-0xfdc(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0xfd0(%rbp),%rsi
mov    -0xfd4(%rbp),%edx
mov    -0xfd8(%rbp),%ecx
mov    -0xfdc(%rbp),%r8d
call   1060 <hhistogram@plt>
mov    %eax,-0xfe0(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0xfd0(%rbp),%rsi
mov    -0xfd4(%rbp),%edx
mov    -0xfd8(%rbp),%ecx
mov    -0xfdc(%rbp),%r8d
call   1090 <vhistogram@plt>
mov    %eax,-0xfe4(%rbp)
cmpl   $0x0,-0xfe0(%rbp)
jne    12a8 <main+0x138>
cmpl   $0x0,-0xfe4(%rbp)
je     12c0 <main+0x150>
lea    0xd76(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e7 <main+0x177>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <main+0x42>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xff0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb8,%rsp
mov    %rsi,(%rsp)
cmp    $0x1,%edi
jg     1196 <main+0x26>
lea    0xe8d(%rip),%rdi
jmp    1254 <main+0xe4>
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r13d
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rax
mov    (%rax,%r13,8),%rdi
lea    0xe41(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123e <main+0xce>
mov    %rax,%rbp
lea    0xe2f(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <wlength@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <hhistogram@plt>
mov    %eax,%r14d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <vhistogram@plt>
or     %r14d,%eax
jne    124d <main+0xdd>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x1,%r13
cmp    %r13,0x8(%rsp)
jne    11b0 <main+0x40>
jmp    1260 <main+0xf0>
mov    (%rsp),%rax
mov    (%rax,%r13,8),%rdi
call   1080 <perror@plt>
jmp    122d <main+0xbd>
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1262 <main+0xf2>
xor    %eax,%eax
add    $0xfb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Missing input files!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [16 x i8] c"Error Occured!\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 [1000 x i32]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %73
19: ; preds = %2
store i32 1, i32* %6
br label %20
20: ; preds = %69, %19
%21 = load i32, i32* %6
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %72
24: ; preds = %20
%25 = load i8**, i8*** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %7
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %40
33: ; preds = %24
%34 = load i8**, i8*** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @perror(i8* %38)
br label %69
40: ; preds = %24
%41 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %41, i32** %8
%42 = load i32*, i32** %7
%43 = getelementptr inbounds [1000 x i32], [1000 x i32]* %9, i64 0, i64 0
%44 = call i32 @wlength(i32* %42, i32* %43)
store i32 %44, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%45 = load i32*, i32** %8
%46 = getelementptr inbounds [1000 x i32], [1000 x i32]* %9, i64 0, i64 0
%47 = load i32, i32* %10
%48 = load i32, i32* %11
%49 = load i32, i32* %12
%50 = call i32 @hhistogram(i32* %45, i32* %46, i32 %47, i32 %48, i32 %49)
store i32 %50, i32* %13
%51 = load i32*, i32** %8
%52 = getelementptr inbounds [1000 x i32], [1000 x i32]* %9, i64 0, i64 0
%53 = load i32, i32* %10
%54 = load i32, i32* %11
%55 = load i32, i32* %12
%56 = call i32 @vhistogram(i32* %51, i32* %52, i32 %53, i32 %54, i32 %55)
store i32 %56, i32* %14
%57 = load i32, i32* %13
%58 = icmp ne i32 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %40
%60 = load i32, i32* %14
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59, %40
%63 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %73
64: ; preds = %59
%65 = load i32*, i32** %7
%66 = call i32 @fclose(i32* %65)
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %64, %33
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %20
72: ; preds = %20
store i32 0, i32* %3
br label %73
73: ; preds = %72, %62, %17
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@str = [15 x i8] c"Error Occured!\00"
@str.5 = [21 x i8] c"Missing input files!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i32]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
br label %38
7: ; preds = %2
%8 = bitcast [1000 x i32]* %3 to i8*
%9 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %7, %33
%12 = phi i64 [ 1, %7 ], [ %34, %33 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %13
%19 = call i32 @perror(i8* %18)
br label %33
20: ; preds = %11
%21 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @wlength(i32* %15, i32* %9)
%23 = call i32 @hhistogram(i32* %21, i32* %9, i32 %22, i32 0, i32 0)
%24 = call i32 @vhistogram(i32* %21, i32* %9, i32 %22, i32 0, i32 0)
%25 = icmp ne i32 %23, 0
%26 = icmp ne i32 %24, 0
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %36
30: ; preds = %20
%31 = call i32 @fclose(i32* %15)
%32 = call i32 @fclose(i32* %21)
br label %33
33: ; preds = %30, %17
%34 = add nuw nsw i64 %12, 1
%35 = icmp eq i64 %34, %10
br i1 %35, label %36, label %11
36: ; preds = %33, %28
%37 = phi i32 [ 1, %28 ], [ 0, %33 ]
br label %38
38: ; preds = %36, %5
%39 = phi i32 [ 1, %5 ], [ %37, %36 ]
ret i32 %39
}