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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_byte(char *);
int /*<<< orphan*/ stderr;
int read_record(FILE *file, uint8_t *data, int size) {
  char line[255 * 3];
  const char *p;
  uint8_t sum;
  int length, i;
  if (!fgets(line, sizeof(line), file))
    return 0;
  if (*line != ':') {
    fprintf(stderr, "syntax error: record does not begin with a colon\n");
    exit(1);
  }
  length = get_byte(line + 1) + 3;
  if (length + 1 > size) {
    fprintf(stderr, "record is too long for buffer (%d bytes >= %d bytes)\n",
            length, size);
    exit(1);
  }
  sum = length - 3;
  for (i = 0; i != length + 1; i++) {
    data[i] = get_byte(line + 2 * i + 3);
    sum += data[i];
  }
  if (sum) {
    fprintf(stderr, "record checksum error (0x%02x)\n", data[length]);
    exit(1);
  }
  for (p = line + 2 * length + 5; *p; p++)
    if (*p != '\n' && *p != '\r') {
      fprintf(stderr, "record ends in \\%03o instead of \\n or \\r\n", *p);
      exit(1);
    }
  return length;
}


x86 assembly (clang, -O0):
<read_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2fd,%esi
call   1030 <fgets@plt>
cmp    $0x0,%eax
jne    1180 <read_record+0x40>
movl   $0x0,-0x4(%rbp)
jmp    1375 <read_record+0x235>
movsbl -0x320(%rbp),%eax
cmp    $0x3a,%eax
je     11b1 <read_record+0x71>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x320(%rbp),%rdi
add    $0x1,%rdi
call   1040 <get_byte@plt>
add    $0x3,%eax
mov    %eax,-0x330(%rbp)
mov    -0x330(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jle    1206 <read_record+0xc6>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x330(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x330(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x32c(%rbp)
movl   $0x0,-0x334(%rbp)
mov    -0x334(%rbp),%eax
mov    -0x330(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1292 <read_record+0x152>
lea    -0x320(%rbp),%rdi
mov    -0x334(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
add    $0x3,%rdi
call   1040 <get_byte@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x334(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x334(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x32c(%rbp),%eax
mov    %eax,-0x32c(%rbp)
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    121f <read_record+0xdf>
cmpl   $0x0,-0x32c(%rbp)
je     12ce <read_record+0x18e>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0x330(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x320(%rbp),%rax
mov    -0x330(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x5,%rax
mov    %rax,-0x328(%rbp)
mov    -0x328(%rbp),%rax
cmpb   $0x0,(%rax)
je     136c <read_record+0x22c>
mov    -0x328(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1350 <read_record+0x210>
mov    -0x328(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
je     1350 <read_record+0x210>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
mov    -0x328(%rbp),%rax
movsbl (%rax),%edx
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1355 <read_record+0x215>
mov    -0x328(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x328(%rbp)
jmp    12ef <read_record+0x1af>
mov    -0x330(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_record>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x308,%rsp
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x2fd,%esi
call   1030 <fgets@plt>
test   %eax,%eax
je     1216 <read_record+0xd6>
cmpb   $0x3a,(%rsp)
jne    1247 <read_record+0x107>
lea    0x1(%rsp),%rdi
call   1040 <get_byte@plt>
mov    %eax,%ebx
lea    0x3(%rbx),%r14d
lea    0x4(%rbx),%eax
cmp    %ebp,%eax
jg     1268 <read_record+0x128>
test   %eax,%eax
je     122e <read_record+0xee>
mov    %eax,%r13d
lea    0x3(%rsp),%r12
add    %r13,%r13
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%rdi
call   1040 <get_byte@plt>
mov    %eax,(%r15,%rbp,2)
add    %eax,%ebx
add    $0x2,%rbp
cmp    %rbp,%r13
jne    11b0 <read_record+0x70>
test   %ebx,%ebx
jne    122e <read_record+0xee>
lea    (%r14,%r14,1),%eax
cltq
add    %rsp,%rax
add    $0x5,%rax
jmp    11e4 <read_record+0xa4>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
movsbl (%rax),%edx
cmp    $0xa,%edx
je     11e0 <read_record+0xa0>
cmp    $0xd,%dl
je     11e0 <read_record+0xa0>
test   %dl,%dl
je     1219 <read_record+0xd9>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x308,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
movslq %r14d,%rax
mov    (%r15,%rax,4),%edx
lea    0xe23(%rip),%rsi
jmp    1205 <read_record+0xc5>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"syntax error: record does not begin with a colon\0A\00"
@.str.1 = [54 x i8] c"record is too long for buffer (%d bytes >= %d bytes)\0A\00"
@.str.2 = [32 x i8] c"record checksum error (0x%02x)\0A\00"
@.str.3 = [42 x i8] c"record ends in \\%03o instead of \\n or \\r\0A\00"
define i32 @read_record(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [765 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%13 = getelementptr inbounds [765 x i8], [765 x i8]* %8, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i32 @fgets(i8* %13, i32 765, i32* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %3
store i32 0, i32* %4
br label %118
18: ; preds = %3
%19 = getelementptr inbounds [765 x i8], [765 x i8]* %8, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 58
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = getelementptr inbounds [765 x i8], [765 x i8]* %8, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i32 @get_byte(i8* %29)
%31 = add nsw i32 %30, 3
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %7
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %42
36: ; preds = %27
%37 = load i32, i32* @stderr
%38 = load i32, i32* %11
%39 = load i32, i32* %7
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %27
%43 = load i32, i32* %11
%44 = sub nsw i32 %43, 3
store i32 %44, i32* %10
store i32 0, i32* %12
br label %45
45: ; preds = %69, %42
%46 = load i32, i32* %12
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
%49 = icmp ne i32 %46, %48
br i1 %49, label %50, label %72
50: ; preds = %45
%51 = getelementptr inbounds [765 x i8], [765 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* %12
%53 = mul nsw i32 2, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = getelementptr inbounds i8, i8* %55, i64 3
%57 = call i32 @get_byte(i8* %56)
%58 = load i32*, i32** %6
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
store i32 %57, i32* %61
%62 = load i32*, i32** %6
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
%67 = load i32, i32* %10
%68 = add nsw i32 %67, %66
store i32 %68, i32* %10
br label %69
69: ; preds = %50
%70 = load i32, i32* %12
%71 = add nsw i32 %70, 1
store i32 %71, i32* %12
br label %45
72: ; preds = %45
%73 = load i32, i32* %10
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %84
75: ; preds = %72
%76 = load i32, i32* @stderr
%77 = load i32*, i32** %6
%78 = load i32, i32* %11
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
%81 = load i32, i32* %80
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %72
%85 = getelementptr inbounds [765 x i8], [765 x i8]* %8, i64 0, i64 0
%86 = load i32, i32* %11
%87 = mul nsw i32 2, %86
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %85, i64 %88
%90 = getelementptr inbounds i8, i8* %89, i64 5
store i8* %90, i8** %9
br label %91
91: ; preds = %113, %84
%92 = load i8*, i8** %9
%93 = load i8, i8* %92
%94 = icmp ne i8 %93, 0
br i1 %94, label %95, label %116
95: ; preds = %91
%96 = load i8*, i8** %9
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp ne i32 %98, 10
br i1 %99, label %100, label %112
100: ; preds = %95
%101 = load i8*, i8** %9
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp ne i32 %103, 13
br i1 %104, label %105, label %112
105: ; preds = %100
%106 = load i32, i32* @stderr
%107 = load i8*, i8** %9
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %109)
%111 = call i32 @exit(i32 1)
unreachable
112: ; preds = %100, %95
br label %113
113: ; preds = %112
%114 = load i8*, i8** %9
%115 = getelementptr inbounds i8, i8* %114, i32 1
store i8* %115, i8** %9
br label %91
116: ; preds = %91
%117 = load i32, i32* %11
store i32 %117, i32* %4
br label %118
118: ; preds = %116, %17
%119 = load i32, i32* %4
ret i32 %119
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"syntax error: record does not begin with a colon\0A\00"
@.str.1 = [54 x i8] c"record is too long for buffer (%d bytes >= %d bytes)\0A\00"
@.str.2 = [32 x i8] c"record checksum error (0x%02x)\0A\00"
@.str.3 = [42 x i8] c"record ends in \\%03o instead of \\n or \\r\0A\00"
define i32 @read_record(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca [765 x i8]
%5 = getelementptr inbounds [765 x i8], [765 x i8]* %4, i64 0, i64 0
%6 = call i32 @fgets(i8* %5, i32 765, i32* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %64, label %8
8: ; preds = %3
%9 = load i8, i8* %5
%10 = icmp eq i8 %9, 58
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = getelementptr inbounds [765 x i8], [765 x i8]* %4, i64 0, i64 1
%17 = call i32 @get_byte(i8* %16)
%18 = add nsw i32 %17, 3
%19 = add nsw i32 %17, 4
%20 = icmp sgt i32 %19, %2
br i1 %20, label %25, label %21
21: ; preds = %15
%22 = icmp eq i32 %19, 0
br i1 %22, label %42, label %23
23: ; preds = %21
%24 = zext i32 %19 to i64
br label %29
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %2)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23, %29
%30 = phi i64 [ 0, %23 ], [ %38, %29 ]
%31 = phi i32 [ %17, %23 ], [ %37, %29 ]
%32 = shl nuw nsw i64 %30, 1
%33 = getelementptr inbounds [765 x i8], [765 x i8]* %4, i64 0, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 3
%35 = call i32 @get_byte(i8* %34)
%36 = getelementptr inbounds i32, i32* %1, i64 %30
store i32 %35, i32* %36
%37 = add nsw i32 %35, %31
%38 = add nuw nsw i64 %30, 1
%39 = icmp eq i64 %38, %24
br i1 %39, label %40, label %29
40: ; preds = %29
%41 = icmp eq i32 %37, 0
br i1 %41, label %49, label %42
42: ; preds = %21, %40
%43 = load i32, i32* @stderr
%44 = sext i32 %18 to i64
%45 = getelementptr inbounds i32, i32* %1, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %40
%50 = shl nsw i32 %18, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [765 x i8], [765 x i8]* %4, i64 0, i64 %51
%53 = getelementptr inbounds i8, i8* %52, i64 5
br label %54
54: ; preds = %62, %49
%55 = phi i8* [ %53, %49 ], [ %63, %62 ]
%56 = load i8, i8* %55
switch i8 %56, label %57 [
i8 0, label %64
i8 10, label %62
i8 13, label %62
]
57: ; preds = %54
%58 = sext i8 %56 to i32
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %54, %54
%63 = getelementptr inbounds i8, i8* %55, i64 1
br label %54
64: ; preds = %54, %3
%65 = phi i32 [ 0, %3 ], [ %18, %54 ]
ret i32 %65
}