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

/* Variables and functions */
int abs(int);
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int check_result(short *taps, char tap_filename[100]) {
  FILE *fp;
  char buffer[255];
  printf("FN: %s\n", tap_filename);
  fp = fopen(tap_filename, "r");
  uint8_t k = 0;
  while (fgets(buffer, 255, (FILE *)fp)) {
    int tap = atoi(buffer);
    if (abs(tap - taps[k]) > 2) {
      fclose(fp);
      printf("Error: Tap missmatch\n");
      return -2;
    }
    k++;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<check_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1234 <check_result+0xd4>
lea    -0x120(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x12c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x128(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
sub    %eax,%edi
call   1030 <abs@plt>
cmp    $0x2,%eax
jle    121d <check_result+0xbd>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1244 <check_result+0xe4>
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
jmp    11a4 <check_result+0x44>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_result>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe86(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7d(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e2 <check_result+0x82>
mov    %rsp,%rbp
xchg   %ax,%ax
mov    %rbp,%rdi
call   1080 <atoi@plt>
movswl (%rbx),%ecx
sub    %ecx,%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
cmp    $0x3,%ecx
jae    11ec <check_result+0x8c>
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
add    $0x2,%rbx
test   %rax,%rax
jne    11b0 <check_result+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    1206 <check_result+0xa6>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%r14d
mov    %r14d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"FN: %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Error: Tap missmatch\0A\00"
define i32 @check_result(i16* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i16*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [255 x i8]
%8 = alloca i64
%9 = alloca i32
store i16* %0, i16** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
store i64 0, i64* %8
br label %14
14: ; preds = %35, %2
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i64 @fgets(i8* %15, i32 255, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %14
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = load i16*, i16** %4
%24 = load i64, i64* %8
%25 = getelementptr inbounds i16, i16* %23, i64 %24
%26 = load i16, i16* %25
%27 = sext i16 %26 to i32
%28 = sub nsw i32 %22, %27
%29 = call i32 @abs(i32 %28)
%30 = icmp sgt i32 %29, 2
br i1 %30, label %31, label %35
31: ; preds = %19
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %3
br label %41
35: ; preds = %19
%36 = load i64, i64* %8
%37 = add i64 %36, 1
store i64 %37, i64* %8
br label %14
38: ; preds = %14
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %31
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [8 x i8] c"FN: %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@str = [21 x i8] c"Error: Tap missmatch\00"
define i32 @check_result(i16* nocapture %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i64 @fgets(i8* %4, i32 255, i32* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %25, label %13
9: ; preds = %13
%10 = add i64 %14, 1
%11 = call i64 @fgets(i8* %4, i32 255, i32* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %2, %9
%14 = phi i64 [ %10, %9 ], [ 0, %2 ]
%15 = call i32 @atoi(i8* %4)
%16 = getelementptr inbounds i16, i16* %0, i64 %14
%17 = load i16, i16* %16
%18 = sext i16 %17 to i32
%19 = sub nsw i32 %15, %18
%20 = call i32 @llvm.abs.i32(i32 %19, i1 true)
%21 = icmp ugt i32 %20, 2
br i1 %21, label %22, label %9
22: ; preds = %13
%23 = call i32 @fclose(i32* %6)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %27
25: ; preds = %9, %2
%26 = call i32 @fclose(i32* %6)
br label %27
27: ; preds = %22, %25
%28 = phi i32 [ 0, %25 ], [ -2, %22 ]
ret i32 %28
}