#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 EOF;
int fgetc(int /*<<< orphan*/ *);
unsigned int finhb(int /*<<< orphan*/ *);
unsigned int finhw(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(unsigned int, int /*<<< orphan*/ *);
int record(FILE *infile, FILE *outfile) {
  int rectype, nbytes, c;
  unsigned int chksum, loadaddr;
  do {
    c = fgetc(infile);
    if (c == EOF)
      return EOF;
    if (c != 0x00 && c != 0x0D && c != 0x0A && c != 'S')
      return 'S';
  } while (c != 'S');
  rectype = fgetc(infile);
  c = finhb(infile);
  chksum = c;
  nbytes = c - 3;
  loadaddr = finhw(infile);
  chksum += (loadaddr >> 8) & 0xFF;
  chksum += loadaddr & 0xFF;
  switch (rectype) {
  case '1':
    if (!nbytes)
      break;
    fputc(0x02, outfile);
    fputc((loadaddr >> 8) & 0xFF, outfile);
    fputc(loadaddr & 0xFF, outfile);
    fputc(nbytes, outfile);
    while (nbytes--) {
      c = finhb(infile);
      chksum += c;
      fputc(c, outfile);
    }
    break;
  case '9':
    if (!loadaddr)
      break;
    fputc(0x16, outfile);
    fputc((loadaddr >> 8) & 0xFF, outfile);
    fputc(loadaddr & 0xFF, outfile);
    break;
  case '0':
  case '5':
    while (nbytes--) {
      c = finhb(infile);
      chksum += c;
    }
    break;
  default:
    return 'R';
  }
  chksum += finhb(infile);
  if (chksum & 0xFF != 0xFF)
    return 'C';
  return rectype;
}


x86 assembly (clang, -O0):
<record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%eax
jne    117f <record+0x3f>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <record+0x242>
cmpl   $0x0,-0x24(%rbp)
je     11b3 <record+0x73>
cmpl   $0xd,-0x24(%rbp)
je     11b3 <record+0x73>
cmpl   $0xa,-0x24(%rbp)
je     11b3 <record+0x73>
cmpl   $0x53,-0x24(%rbp)
je     11b3 <record+0x73>
movl   $0x53,-0x4(%rbp)
jmp    1382 <record+0x242>
jmp    11b8 <record+0x78>
cmpl   $0x53,-0x24(%rbp)
jne    1150 <record+0x10>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <finhb@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0xfffffffd,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <finhw@plt>
mov    %eax,-0x2c(%rbp)
movzbl -0x2b(%rbp),%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
movzbl -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x9,%eax
ja     1346 <record+0x206>
mov    -0x38(%rbp),%rax
lea    0xdd3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x20(%rbp)
jne    1245 <record+0x105>
jmp    1352 <record+0x212>
mov    -0x18(%rbp),%rsi
mov    $0x2,%edi
call   1050 <fputc@plt>
mov    -0x2c(%rbp),%edi
shr    $0x8,%edi
and    $0xff,%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x2c(%rbp),%edi
and    $0xff,%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
je     12c0 <record+0x180>
mov    -0x10(%rbp),%rdi
call   1060 <finhb@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1286 <record+0x146>
jmp    1352 <record+0x212>
cmpl   $0x0,-0x2c(%rbp)
jne    12d4 <record+0x194>
jmp    1352 <record+0x212>
mov    -0x18(%rbp),%rsi
mov    $0x16,%edi
call   1050 <fputc@plt>
mov    -0x2c(%rbp),%edi
shr    $0x8,%edi
and    $0xff,%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x2c(%rbp),%edi
and    $0xff,%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1352 <record+0x212>
jmp    1313 <record+0x1d3>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
je     1341 <record+0x201>
mov    -0x10(%rbp),%rdi
call   1060 <finhb@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1313 <record+0x1d3>
jmp    1352 <record+0x212>
movl   $0x52,-0x4(%rbp)
jmp    1382 <record+0x242>
mov    -0x10(%rbp),%rdi
call   1060 <finhb@plt>
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
and    $0x0,%eax
cmp    $0x0,%eax
je     137c <record+0x23c>
movl   $0x43,-0x4(%rbp)
jmp    1382 <record+0x242>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<record>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
call   1040 <fgetc@plt>
mov    0x2e8b(%rip),%rbp
cmp    0x0(%rbp),%eax
je     127a <record+0x13a>
mov    $0x2401,%ebx
nopl   0x0(%rax,%rax,1)
cmp    $0xd,%eax
ja     118c <record+0x4c>
bt     %eax,%ebx
jae    118c <record+0x4c>
mov    %r13,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%rbp),%eax
jne    1170 <record+0x30>
jmp    127a <record+0x13a>
cmp    $0x53,%eax
mov    $0x53,%eax
jne    127a <record+0x13a>
mov    %r13,%rdi
call   1040 <fgetc@plt>
mov    %eax,%r15d
mov    %r13,%rdi
call   1060 <finhb@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <finhw@plt>
mov    %eax,%ecx
mov    $0x52,%eax
lea    -0x30(%r15),%edx
cmp    $0x9,%edx
ja     127a <record+0x13a>
add    $0xfffffffd,%ebp
movzbl %ch,%ebx
movzbl %cl,%r12d
lea    0xe24(%rip),%rsi
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
test   %ebp,%ebp
je     126f <record+0x12f>
nopl   (%rax)
mov    %r13,%rdi
call   1060 <finhb@plt>
add    $0xffffffff,%ebp
jne    11f0 <record+0xb0>
jmp    126f <record+0x12f>
test   %ebp,%ebp
je     126f <record+0x12f>
mov    $0x2,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
nop
mov    %r13,%rdi
call   1060 <finhb@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebp
jne    1230 <record+0xf0>
jmp    126f <record+0x12f>
test   %ecx,%ecx
je     126f <record+0x12f>
mov    $0x16,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r13,%rdi
call   1060 <finhb@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @record(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %11
11: ; preds = %33, %2
%12 = load i32*, i32** %4
%13 = call i32 @fgetc(i32* %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* @EOF
store i32 %18, i32* %3
br label %129
19: ; preds = %11
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 13
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 83
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 83, i32* %3
br label %129
32: ; preds = %28, %25, %22, %19
br label %33
33: ; preds = %32
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 83
br i1 %35, label %11, label %36
36: ; preds = %33
%37 = load i32*, i32** %4
%38 = call i32 @fgetc(i32* %37)
store i32 %38, i32* %6
%39 = load i32*, i32** %4
%40 = call i32 @finhb(i32* %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
store i32 %41, i32* %9
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 3
store i32 %43, i32* %7
%44 = load i32*, i32** %4
%45 = call i32 @finhw(i32* %44)
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = lshr i32 %46, 8
%48 = and i32 %47, 255
%49 = load i32, i32* %9
%50 = add i32 %49, %48
store i32 %50, i32* %9
%51 = load i32, i32* %10
%52 = and i32 %51, 255
%53 = load i32, i32* %9
%54 = add i32 %53, %52
store i32 %54, i32* %9
%55 = load i32, i32* %6
switch i32 %55, label %117 [
i32 49, label %56
i32 57, label %89
i32 48, label %105
i32 53, label %105
]
56: ; preds = %36
%57 = load i32, i32* %7
%58 = icmp ne i32 %57, 0
br i1 %58, label %60, label %59
59: ; preds = %56
br label %118
60: ; preds = %56
%61 = load i32*, i32** %5
%62 = call i32 @fputc(i32 2, i32* %61)
%63 = load i32, i32* %10
%64 = lshr i32 %63, 8
%65 = and i32 %64, 255
%66 = load i32*, i32** %5
%67 = call i32 @fputc(i32 %65, i32* %66)
%68 = load i32, i32* %10
%69 = and i32 %68, 255
%70 = load i32*, i32** %5
%71 = call i32 @fputc(i32 %69, i32* %70)
%72 = load i32, i32* %7
%73 = load i32*, i32** %5
%74 = call i32 @fputc(i32 %72, i32* %73)
br label %75
75: ; preds = %79, %60
%76 = load i32, i32* %7
%77 = add nsw i32 %76, -1
store i32 %77, i32* %7
%78 = icmp ne i32 %76, 0
br i1 %78, label %79, label %88
79: ; preds = %75
%80 = load i32*, i32** %4
%81 = call i32 @finhb(i32* %80)
store i32 %81, i32* %8
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = add i32 %83, %82
store i32 %84, i32* %9
%85 = load i32, i32* %8
%86 = load i32*, i32** %5
%87 = call i32 @fputc(i32 %85, i32* %86)
br label %75
88: ; preds = %75
br label %118
89: ; preds = %36
%90 = load i32, i32* %10
%91 = icmp ne i32 %90, 0
br i1 %91, label %93, label %92
92: ; preds = %89
br label %118
93: ; preds = %89
%94 = load i32*, i32** %5
%95 = call i32 @fputc(i32 22, i32* %94)
%96 = load i32, i32* %10
%97 = lshr i32 %96, 8
%98 = and i32 %97, 255
%99 = load i32*, i32** %5
%100 = call i32 @fputc(i32 %98, i32* %99)
%101 = load i32, i32* %10
%102 = and i32 %101, 255
%103 = load i32*, i32** %5
%104 = call i32 @fputc(i32 %102, i32* %103)
br label %118
105: ; preds = %36, %36
br label %106
106: ; preds = %110, %105
%107 = load i32, i32* %7
%108 = add nsw i32 %107, -1
store i32 %108, i32* %7
%109 = icmp ne i32 %107, 0
br i1 %109, label %110, label %116
110: ; preds = %106
%111 = load i32*, i32** %4
%112 = call i32 @finhb(i32* %111)
store i32 %112, i32* %8
%113 = load i32, i32* %8
%114 = load i32, i32* %9
%115 = add i32 %114, %113
store i32 %115, i32* %9
br label %106
116: ; preds = %106
br label %118
117: ; preds = %36
store i32 82, i32* %3
br label %129
118: ; preds = %116, %93, %92, %88, %59
%119 = load i32*, i32** %4
%120 = call i32 @finhb(i32* %119)
%121 = load i32, i32* %9
%122 = add i32 %121, %120
store i32 %122, i32* %9
%123 = load i32, i32* %9
%124 = and i32 %123, 0
%125 = icmp ne i32 %124, 0
br i1 %125, label %126, label %127
126: ; preds = %118
store i32 67, i32* %3
br label %129
127: ; preds = %118
%128 = load i32, i32* %6
store i32 %128, i32* %3
br label %129
129: ; preds = %127, %126, %117, %31, %17
%130 = load i32, i32* %3
ret i32 %130
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @record(i32* %0, i32* nocapture %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %48, label %6
6: ; preds = %2, %8
%7 = phi i32 [ %9, %8 ], [ %3, %2 ]
switch i32 %7, label %48 [
i32 83, label %12
i32 0, label %8
i32 10, label %8
i32 13, label %8
]
8: ; preds = %6, %6, %6
%9 = tail call i32 @fgetc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %48, label %6
12: ; preds = %6
%13 = tail call i32 @fgetc(i32* %0)
%14 = tail call i32 @finhb(i32* %0)
%15 = add nsw i32 %14, -3
%16 = tail call i32 @finhw(i32* %0)
%17 = lshr i32 %16, 8
%18 = and i32 %17, 255
%19 = and i32 %16, 255
switch i32 %13, label %48 [
i32 49, label %20
i32 57, label %33
i32 48, label %39
i32 53, label %39
]
20: ; preds = %12
%21 = icmp eq i32 %15, 0
br i1 %21, label %46, label %22
22: ; preds = %20
%23 = tail call i32 @fputc(i32 2, i32* %1)
%24 = tail call i32 @fputc(i32 %18, i32* %1)
%25 = tail call i32 @fputc(i32 %19, i32* %1)
%26 = tail call i32 @fputc(i32 %15, i32* %1)
br label %27
27: ; preds = %22, %27
%28 = phi i32 [ %15, %22 ], [ %29, %27 ]
%29 = add nsw i32 %28, -1
%30 = tail call i32 @finhb(i32* %0)
%31 = tail call i32 @fputc(i32 %30, i32* %1)
%32 = icmp eq i32 %29, 0
br i1 %32, label %46, label %27
33: ; preds = %12
%34 = icmp eq i32 %16, 0
br i1 %34, label %46, label %35
35: ; preds = %33
%36 = tail call i32 @fputc(i32 22, i32* %1)
%37 = tail call i32 @fputc(i32 %18, i32* %1)
%38 = tail call i32 @fputc(i32 %19, i32* %1)
br label %46
39: ; preds = %12, %12
%40 = icmp eq i32 %15, 0
br i1 %40, label %46, label %41
41: ; preds = %39, %41
%42 = phi i32 [ %43, %41 ], [ %15, %39 ]
%43 = add nsw i32 %42, -1
%44 = tail call i32 @finhb(i32* %0)
%45 = icmp eq i32 %43, 0
br i1 %45, label %46, label %41
46: ; preds = %41, %27, %39, %33, %20, %35
%47 = tail call i32 @finhb(i32* %0)
br label %48
48: ; preds = %8, %6, %2, %12, %46
%49 = phi i32 [ %13, %46 ], [ 82, %12 ], [ %3, %2 ], [ %9, %8 ], [ 83, %6 ]
ret i32 %49
}