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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ihex_get_record_information(char *, unsigned char *, unsigned short *,
                                unsigned char *);
int ihex_verify_checksum(char *, unsigned char);
int /*<<< orphan*/ stderr;
int strlen(char *);
int ihex_check_file(FILE *file, size_t *size_p) {
  int error = 0;
  bool completed = false;
  size_t line = 1;
  char input_string[1000];
  *size_p = 0;
  while (fgets(input_string, sizeof(input_string) - 1, file) && !completed &&
         !error) {
    unsigned char reclen;
    unsigned short load_offset;
    unsigned char rectyp;
    if (strlen(input_string) >= (sizeof(input_string) - 1)) {
      fprintf(stderr, "Error on line %u; line too long.\n", (unsigned int)line);
      error = 1;
    }
    if (!error && (input_string[0] != ':')) {
      fprintf(stderr, "Error on line %u; record does not start with :.\n",
              (unsigned int)line);
      error = 1;
    }
    if (!error) {
      error = ihex_get_record_information(input_string, &reclen, &load_offset,
                                          &rectyp);
      if (error) {
        fprintf(stderr, "Error on line %u; cannot read record fields.\n",
                (unsigned int)line);
        error = 1;
      }
    }
    if (!error) {
      error = ihex_verify_checksum(input_string, reclen);
      if (error) {
        fprintf(stderr, "Checksum for line %u incorrect.\n",
                (unsigned int)line);
      } else {
        switch (rectyp) {
        case (0x00):
        case (0x02):
        case (0x03):
        case (0x04):
        case (0x05):
          (*size_p)++;
          break;
        case (0x01):
          completed = true;
          break;
        default:
          fprintf(stderr, "Unknown record detected.\n");
          error = 1;
          break;
        }
      }
    }
    line++;
  }
  if (!completed) {
    fprintf(stderr, "No EOF record present.\n");
    error = 1;
  }
  return error;
}


x86 assembly (clang, -O0):
<ihex_check_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3e7,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x416(%rbp)
je     11cf <ihex_check_file+0x7f>
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x416(%rbp)
jne    11cf <ihex_check_file+0x7f>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x416(%rbp)
mov    -0x416(%rbp),%al
test   $0x1,%al
jne    11e2 <ihex_check_file+0x92>
jmp    13a8 <ihex_check_file+0x258>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x3e7,%rax
jb     1220 <ihex_check_file+0xd0>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    125e <ihex_check_file+0x10e>
movsbl -0x410(%rbp),%eax
cmp    $0x3a,%eax
je     125e <ihex_check_file+0x10e>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12bf <ihex_check_file+0x16f>
lea    -0x410(%rbp),%rdi
lea    -0x411(%rbp),%rsi
lea    -0x414(%rbp),%rdx
lea    -0x415(%rbp),%rcx
call   1070 <ihex_get_record_information@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12ba <ihex_check_file+0x16a>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    12bf <ihex_check_file+0x16f>
cmpl   $0x0,-0x14(%rbp)
jne    1397 <ihex_check_file+0x247>
lea    -0x410(%rbp),%rdi
movzbl -0x411(%rbp),%esi
call   1030 <ihex_verify_checksum@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     130b <ihex_check_file+0x1bb>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1392 <ihex_check_file+0x242>
movzbl -0x415(%rbp),%eax
mov    %eax,-0x41c(%rbp)
test   %eax,%eax
je     1350 <ihex_check_file+0x200>
jmp    1325 <ihex_check_file+0x1d5>
mov    -0x41c(%rbp),%eax
sub    $0x1,%eax
je     1363 <ihex_check_file+0x213>
jmp    1339 <ihex_check_file+0x1e9>
mov    -0x41c(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x3,%eax
ja     136f <ihex_check_file+0x21f>
jmp    1350 <ihex_check_file+0x200>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    138d <ihex_check_file+0x23d>
movl   $0x1,-0x18(%rbp)
jmp    138d <ihex_check_file+0x23d>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
lea    0xd23(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1392 <ihex_check_file+0x242>
jmp    1397 <ihex_check_file+0x247>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1184 <ihex_check_file+0x34>
cmpl   $0x0,-0x18(%rbp)
jne    13d0 <ihex_check_file+0x280>
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
lea    0xcfa(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihex_check_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rdi,%r15
mov    %rsi,0x8(%rsp)
movq   $0x0,(%rsi)
lea    0x10(%rsp),%rdi
mov    $0x3e7,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12a0 <ihex_check_file+0x150>
mov    $0x1,%ebp
lea    0x10(%rsp),%rbx
mov    0x2e44(%rip),%r14
xor    %r12d,%r12d
nop
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x3e7,%eax
jb     11c0 <ihex_check_file+0x70>
mov    (%r14),%edi
lea    0xe47(%rip),%rsi
jmp    11fa <ihex_check_file+0xaa>
nopl   0x0(%rax,%rax,1)
cmpb   $0x3a,0x10(%rsp)
jne    11f0 <ihex_check_file+0xa0>
mov    %rbx,%rdi
lea    0x5(%rsp),%rsi
lea    0x6(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1070 <ihex_get_record_information@plt>
test   %eax,%eax
je     1231 <ihex_check_file+0xe1>
mov    (%r14),%edi
lea    0xe67(%rip),%rsi
jmp    11fa <ihex_check_file+0xaa>
xchg   %ax,%ax
mov    (%r14),%edi
lea    0xe28(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%r13d
mov    %rbx,%rdi
mov    $0x3e7,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     129b <ihex_check_file+0x14b>
test   %r12d,%r12d
jne    129b <ihex_check_file+0x14b>
add    $0x1,%ebp
test   %r13d,%r13d
je     11a0 <ihex_check_file+0x50>
jmp    129b <ihex_check_file+0x14b>
movzbl 0x5(%rsp),%esi
mov    %rbx,%rdi
call   1030 <ihex_verify_checksum@plt>
test   %eax,%eax
je     125a <ihex_check_file+0x10a>
mov    %eax,%r13d
mov    (%r14),%edi
lea    0xe32(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1209 <ihex_check_file+0xb9>
xor    %r13d,%r13d
movzbl 0x4(%rsp),%eax
lea    -0x2(%rax),%ecx
cmp    $0x4,%cl
jb     1272 <ihex_check_file+0x122>
cmp    $0x1,%al
je     127d <ihex_check_file+0x12d>
test   %al,%al
jne    1285 <ihex_check_file+0x135>
mov    0x8(%rsp),%rax
addq   $0x1,(%rax)
jmp    1209 <ihex_check_file+0xb9>
mov    $0x1,%r12d
jmp    1209 <ihex_check_file+0xb9>
mov    (%r14),%edi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1203 <ihex_check_file+0xb3>
test   %r12d,%r12d
jne    12bd <ihex_check_file+0x16d>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%r13d
mov    %r13d,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Error on line %u; line too long.\0A\00"
@.str.1 = [49 x i8] c"Error on line %u; record does not start with :.\0A\00"
@.str.2 = [46 x i8] c"Error on line %u; cannot read record fields.\0A\00"
@.str.3 = [33 x i8] c"Checksum for line %u incorrect.\0A\00"
@.str.4 = [26 x i8] c"Unknown record detected.\0A\00"
@.str.5 = [24 x i8] c"No EOF record present.\0A\00"
define i32 @ihex_check_file(i32* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca [1000 x i8]
%9 = alloca i8
%10 = alloca i16
%11 = alloca i8
store i32* %0, i32** %3
store i64* %1, i64** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i64 1, i64* %7
%12 = load i64*, i64** %4
store i64 0, i64* %12
br label %13
13: ; preds = %91, %2
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i64 @fgets(i8* %14, i32 999, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br label %25
25: ; preds = %21, %18, %13
%26 = phi i1 [ false, %18 ], [ false, %13 ], [ %24, %21 ]
br i1 %26, label %27, label %94
27: ; preds = %25
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = icmp uge i64 %30, 999
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i64, i64* %7
%35 = trunc i64 %34 to i32
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 1, i32* %5
br label %37
37: ; preds = %32, %27
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %37
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 58
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = load i64, i64* %7
%48 = trunc i64 %47 to i32
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %48)
store i32 1, i32* %5
br label %50
50: ; preds = %45, %40, %37
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %64, label %53
53: ; preds = %50
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%55 = call i32 @ihex_get_record_information(i8* %54, i8* %9, i16* %10, i8* %11)
store i32 %55, i32* %5
%56 = load i32, i32* %5
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = load i64, i64* %7
%61 = trunc i64 %60 to i32
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %61)
store i32 1, i32* %5
br label %63
63: ; preds = %58, %53
br label %64
64: ; preds = %63, %50
%65 = load i32, i32* %5
%66 = icmp ne i32 %65, 0
br i1 %66, label %91, label %67
67: ; preds = %64
%68 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%69 = load i8, i8* %9
%70 = call i32 @ihex_verify_checksum(i8* %68, i8 zeroext %69)
store i32 %70, i32* %5
%71 = load i32, i32* %5
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %67
%74 = load i32, i32* @stderr
%75 = load i64, i64* %7
%76 = trunc i64 %75 to i32
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %76)
br label %90
78: ; preds = %67
%79 = load i8, i8* %11
%80 = zext i8 %79 to i32
switch i32 %80, label %86 [
i32 0, label %81
i32 2, label %81
i32 3, label %81
i32 4, label %81
i32 5, label %81
i32 1, label %85
]
81: ; preds = %78, %78, %78, %78, %78
%82 = load i64*, i64** %4
%83 = load i64, i64* %82
%84 = add i64 %83, 1
store i64 %84, i64* %82
br label %89
85: ; preds = %78
store i32 1, i32* %6
br label %89
86: ; preds = %78
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %5
br label %89
89: ; preds = %86, %85, %81
br label %90
90: ; preds = %89, %73
br label %91
91: ; preds = %90, %64
%92 = load i64, i64* %7
%93 = add i64 %92, 1
store i64 %93, i64* %7
br label %13
94: ; preds = %25
%95 = load i32, i32* %6
%96 = icmp ne i32 %95, 0
br i1 %96, label %100, label %97
97: ; preds = %94
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %5
br label %100
100: ; preds = %97, %94
%101 = load i32, i32* %5
ret i32 %101
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Error on line %u; line too long.\0A\00"
@.str.1 = [49 x i8] c"Error on line %u; record does not start with :.\0A\00"
@.str.2 = [46 x i8] c"Error on line %u; cannot read record fields.\0A\00"
@.str.3 = [33 x i8] c"Checksum for line %u incorrect.\0A\00"
@.str.4 = [26 x i8] c"Unknown record detected.\0A\00"
@.str.5 = [24 x i8] c"No EOF record present.\0A\00"
define i32 @ihex_check_file(i32* nocapture %0, i64* nocapture %1) {
%3 = alloca [1000 x i8]
%4 = alloca i8
%5 = alloca i16
%6 = alloca i8
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
store i64 0, i64* %1
%8 = call i64 @fgets(i8* %7, i32 999, i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %63, label %10
10: ; preds = %2
%11 = bitcast i16* %5 to i8*
br label %12
12: ; preds = %10, %51
%13 = phi i64 [ 1, %10 ], [ %54, %51 ]
%14 = phi i32 [ 0, %10 ], [ %53, %51 ]
%15 = call i32 @strlen(i8* %7)
%16 = icmp ugt i32 %15, 998
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = trunc i64 %13 to i32
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %51
21: ; preds = %12
%22 = load i8, i8* %7
%23 = icmp eq i8 %22, 58
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = trunc i64 %13 to i32
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %51
28: ; preds = %21
%29 = call i32 @ihex_get_record_information(i8* %7, i8* %4, i16* %5, i8* %6)
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = trunc i64 %13 to i32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %51
35: ; preds = %28
%36 = load i8, i8* %4
%37 = call i32 @ihex_verify_checksum(i8* %7, i8 zeroext %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = trunc i64 %13 to i32
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %51
43: ; preds = %35
%44 = load i8, i8* %6
switch i8 %44, label %48 [
i8 0, label %45
i8 2, label %45
i8 3, label %45
i8 4, label %45
i8 5, label %45
i8 1, label %51
]
45: ; preds = %43, %43, %43, %43, %43
%46 = load i64, i64* %1
%47 = add i64 %46, 1
store i64 %47, i64* %1
br label %51
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %17, %24, %31, %43, %39, %48, %45
%52 = phi i32 [ %37, %39 ], [ 1, %48 ], [ 0, %45 ], [ 0, %43 ], [ 1, %31 ], [ 1, %24 ], [ 1, %17 ]
%53 = phi i32 [ %14, %39 ], [ %14, %48 ], [ %14, %45 ], [ 1, %43 ], [ %14, %31 ], [ %14, %24 ], [ %14, %17 ]
%54 = add i64 %13, 1
%55 = call i64 @fgets(i8* %7, i32 999, i32* %0)
%56 = icmp eq i64 %55, 0
%57 = icmp ne i32 %53, 0
%58 = select i1 %56, i1 true, i1 %57
%59 = icmp eq i32 %52, 0
%60 = xor i1 %58, true
%61 = select i1 %60, i1 %59, i1 false
br i1 %61, label %12, label %62
62: ; preds = %51
br i1 %57, label %66, label %63
63: ; preds = %2, %62
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %66
66: ; preds = %63, %62
%67 = phi i32 [ %52, %62 ], [ 1, %63 ]
ret i32 %67
}