#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
int inputSize() {
  int a = 0, b = 0, x;
  FILE *fileA = fopen("./examples/q1/inputA.txt", "r");
  FILE *fileB = fopen("./examples/q1/inputB.txt", "r");
  if (fileA == NULL || fileB == NULL) {
    printf("\nERROR: FILE_FAILED_TO_OPEN");
    exit(0);
  }
  while (!feof(fileA)) {
    fscanf(fileA, "%d ", &x);
    a++;
  }
  while (!feof(fileB)) {
    fscanf(fileB, "%d ", &x);
    b++;
  }
  if (a == 0 || b == 0 || a != b) {
    printf("\nERROR: FILE_INPUT_SIZE_INVALID");
    exit(0);
  }
  fclose(fileA);
  fclose(fileB);
  return a;
}


x86 assembly (clang, -O0):
<inputSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ba <inputSize+0x5a>
cmpq   $0x0,-0x20(%rbp)
jne    11cd <inputSize+0x6d>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    11d2 <inputSize+0x72>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f0 <inputSize+0x90>
jmp    1212 <inputSize+0xb2>
mov    -0x18(%rbp),%rdi
lea    0xe55(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <inputSize+0x72>
jmp    1217 <inputSize+0xb7>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1235 <inputSize+0xd5>
jmp    1257 <inputSize+0xf7>
mov    -0x20(%rbp),%rdi
lea    0xe10(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1217 <inputSize+0xb7>
cmpl   $0x0,-0x4(%rbp)
je     1277 <inputSize+0x117>
cmpl   $0x0,-0x8(%rbp)
je     1277 <inputSize+0x117>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     128a <inputSize+0x12a>
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputSize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0xea0(%rip),%rbx
mov    %rbx,%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
call   1070 <fopen@plt>
test   %r14,%r14
je     125f <inputSize+0xff>
mov    %rax,%r13
test   %rax,%rax
je     125f <inputSize+0xff>
mov    %r14,%rdi
call   1060 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    11ed <inputSize+0x8d>
xor    %ebx,%ebx
lea    0xe91(%rip),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
add    $0x1,%ebx
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11d0 <inputSize+0x70>
mov    %r13,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1256 <inputSize+0xf6>
lea    0xe50(%rip),%r15
lea    0x4(%rsp),%r12
mov    %ebx,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    %r13,%rdi
call   1060 <feof@plt>
add    $0xffffffff,%ebp
test   %eax,%eax
je     1210 <inputSize+0xb0>
test   %ebx,%ebx
je     1256 <inputSize+0xf6>
test   %ebp,%ebp
jne    1256 <inputSize+0xf6>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf7(%rip),%rdi
jmp    1266 <inputSize+0x106>
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"./examples/q1/inputA.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"./examples/q1/inputB.txt\00"
@.str.3 = [28 x i8] c"\0AERROR: FILE_FAILED_TO_OPEN\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [32 x i8] c"\0AERROR: FILE_INPUT_SIZE_INVALID\00"
define i32 @inputSize() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10, %0
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %10
br label %17
17: ; preds = %22, %16
%18 = load i32*, i32** %4
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32*, i32** %4
%24 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
br label %17
27: ; preds = %17
br label %28
28: ; preds = %33, %27
%29 = load i32*, i32** %5
%30 = call i32 @feof(i32* %29)
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i32*, i32** %5
%35 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %28
38: ; preds = %28
%39 = load i32, i32* %1
%40 = icmp eq i32 %39, 0
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = load i32, i32* %2
%43 = icmp eq i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = load i32, i32* %1
%46 = load i32, i32* %2
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %44, %41, %38
%49 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %44
%52 = load i32*, i32** %4
%53 = call i32 @fclose(i32* %52)
%54 = load i32*, i32** %5
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@.str = [25 x i8] c"./examples/q1/inputA.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"./examples/q1/inputB.txt\00"
@.str.3 = [28 x i8] c"\0AERROR: FILE_FAILED_TO_OPEN\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [32 x i8] c"\0AERROR: FILE_INPUT_SIZE_INVALID\00"
define i32 @inputSize() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %3, null
%6 = icmp eq i32* %4, null
%7 = or i1 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @feof(i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %14
11: ; preds = %0
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %18, %8
%15 = phi i32 [ 0, %8 ], [ %21, %18 ]
%16 = call i32 @feof(i32* %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %24, label %34
18: ; preds = %8, %18
%19 = phi i32 [ %21, %18 ], [ 0, %8 ]
%20 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%21 = add nuw nsw i32 %19, 1
%22 = call i32 @feof(i32* %3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %18, label %14
24: ; preds = %14, %24
%25 = phi i32 [ %27, %24 ], [ 0, %14 ]
%26 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%27 = add nuw nsw i32 %25, 1
%28 = call i32 @feof(i32* %4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %24, label %30
30: ; preds = %24
%31 = icmp ne i32 %15, 0
%32 = icmp eq i32 %15, %27
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %37, label %34
34: ; preds = %14, %30
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %30
%38 = call i32 @fclose(i32* %3)
%39 = call i32 @fclose(i32* %4)
ret i32 %15
}