#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ftell(int /*<<< orphan*/ *);
int record(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  int rectype;
  if (argc != 3) {
    fprintf(
        stderr,
        "Motorola S-record to FLEX binary converter\nUsage: %s infile "
        "outfile\nOutput records are the same size as input records, so may "
        "not\nbe as large as possible even where data is contiguous.\nOutput "
        "is not padded to a multiple of 252 bytes in size.\n",
        argv[0]);
    return EXIT_FAILURE;
  }
  infile = fopen(argv[1], "rt");
  outfile = fopen(argv[2], "wb");
  if (infile == NULL) {
    fprintf(stderr, "Error opening file %s for input.\n", argv[1]);
  } else if (outfile == NULL) {
    fprintf(stderr, "Error opening file %s for output.\n", argv[2]);
  } else {
    do {
      rectype = record(infile, outfile);
    } while (rectype == '0' || rectype == '1' || rectype == '5' ||
             rectype == '9');
    if (rectype != EOF) {
      fprintf(stderr, "Error %c before offset %04X in input file.\n", rectype,
              (int)ftell(infile));
    }
  }
  if (infile != NULL)
    fclose(infile);
  if (outfile != NULL)
    fclose(outfile);
  return (rectype == EOF) ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119f <main+0x4f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <main+0x1de>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf45(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xf30(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fe <main+0xae>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xf07(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12d1 <main+0x181>
cmpq   $0x0,-0x20(%rbp)
jne    122d <main+0xdd>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xefa(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12cc <main+0x17c>
jmp    1232 <main+0xe2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <record@plt>
mov    %eax,-0x24(%rbp)
mov    $0x1,%al
cmpl   $0x30,-0x24(%rbp)
mov    %al,-0x25(%rbp)
je     1279 <main+0x129>
mov    $0x1,%al
cmpl   $0x31,-0x24(%rbp)
mov    %al,-0x25(%rbp)
je     1279 <main+0x129>
mov    $0x1,%al
cmpl   $0x35,-0x24(%rbp)
mov    %al,-0x25(%rbp)
je     1279 <main+0x129>
cmpl   $0x39,-0x24(%rbp)
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1232 <main+0xe2>
mov    -0x24(%rbp),%eax
mov    0x2d5a(%rip),%rcx
cmp    (%rcx),%eax
je     12c7 <main+0x177>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12cc <main+0x17c>
jmp    12d1 <main+0x181>
cmpq   $0x0,-0x18(%rbp)
je     12e5 <main+0x195>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     12f9 <main+0x1a9>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    0x2ce5(%rip),%rcx
cmp    (%rcx),%eax
jne    131c <main+0x1cc>
mov    0x2cb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    1328 <main+0x1d8>
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    1202 <main+0xb2>
mov    0x8(%rbp),%rdi
lea    0xf84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    0x10(%rbp),%rdi
lea    0xf74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %r12,%r12
je     121f <main+0xcf>
test   %r14,%r14
je     1241 <main+0xf1>
movabs $0x223000000000000,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <record@plt>
mov    %eax,%ebp
cmp    $0x39,%eax
ja     11ca <main+0x7a>
mov    %ebp,%eax
bt     %rax,%rbx
jb     11b0 <main+0x60>
mov    0x2e17(%rip),%rax
cmp    (%rax),%ebp
je     125c <main+0x10c>
mov    0x2df8(%rip),%rax
mov    (%rax),%r15d
mov    %r12,%rdi
call   1060 <ftell@plt>
lea    0xf4c(%rip),%rsi
mov    %r15d,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    125c <main+0x10c>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdea(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1285 <main+0x135>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xec6(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r14,%r14
jne    1269 <main+0x119>
jmp    1271 <main+0x121>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%rdx
lea    0xec6(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     1271 <main+0x121>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2d70(%rip),%rax
cmp    (%rax),%ebp
jne    1285 <main+0x135>
mov    0x2d45(%rip),%rax
jmp    128c <main+0x13c>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [243 x i8] c"Motorola S-record to FLEX binary converter\0AUsage: %s infile outfile\0AOutput records are the same size as input records, so may not\0Abe as large as possible even where data is contiguous.\0AOutput is not padded to a multiple of 252 bytes in size.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [34 x i8] c"Error opening file %s for input.\0A\00"
@.str.4 = [35 x i8] c"Error opening file %s for output.\0A\00"
@EOF = global i32 0
@.str.5 = [44 x i8] c"Error %c before offset %04X in input file.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([243 x i8], [243 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %98
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %7
%27 = load i32*, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %35
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %76
35: ; preds = %18
%36 = load i32*, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %75
44: ; preds = %35
br label %45
45: ; preds = %61, %44
%46 = load i32*, i32** %6
%47 = load i32*, i32** %7
%48 = call i32 @record(i32* %46, i32* %47)
store i32 %48, i32* %8
br label %49
49: ; preds = %45
%50 = load i32, i32* %8
%51 = icmp eq i32 %50, 48
br i1 %51, label %61, label %52
52: ; preds = %49
%53 = load i32, i32* %8
%54 = icmp eq i32 %53, 49
br i1 %54, label %61, label %55
55: ; preds = %52
%56 = load i32, i32* %8
%57 = icmp eq i32 %56, 53
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = load i32, i32* %8
%60 = icmp eq i32 %59, 57
br label %61
61: ; preds = %58, %55, %52, %49
%62 = phi i1 [ true, %55 ], [ true, %52 ], [ true, %49 ], [ %60, %58 ]
br i1 %62, label %45, label %63
63: ; preds = %61
%64 = load i32, i32* %8
%65 = load i32, i32* @EOF
%66 = icmp ne i32 %64, %65
br i1 %66, label %67, label %74
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = load i32, i32* %8
%70 = load i32*, i32** %6
%71 = call i64 @ftell(i32* %70)
%72 = trunc i64 %71 to i32
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %69, i32 %72)
br label %74
74: ; preds = %67, %63
br label %75
75: ; preds = %74, %38
br label %76
76: ; preds = %75, %29
%77 = load i32*, i32** %6
%78 = icmp ne i32* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
br label %82
82: ; preds = %79, %76
%83 = load i32*, i32** %7
%84 = icmp ne i32* %83, null
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i32*, i32** %7
%87 = call i32 @fclose(i32* %86)
br label %88
88: ; preds = %85, %82
%89 = load i32, i32* %8
%90 = load i32, i32* @EOF
%91 = icmp eq i32 %89, %90
br i1 %91, label %92, label %94
92: ; preds = %88
%93 = load i32, i32* @EXIT_SUCCESS
br label %96
94: ; preds = %88
%95 = load i32, i32* @EXIT_FAILURE
br label %96
96: ; preds = %94, %92
%97 = phi i32 [ %93, %92 ], [ %95, %94 ]
store i32 %97, i32* %3
br label %98
98: ; preds = %96, %11
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [243 x i8] c"Motorola S-record to FLEX binary converter\0AUsage: %s infile outfile\0AOutput records are the same size as input records, so may not\0Abe as large as possible even where data is contiguous.\0AOutput is not padded to a multiple of 252 bytes in size.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [34 x i8] c"Error opening file %s for input.\0A\00"
@.str.4 = [35 x i8] c"Error opening file %s for output.\0A\00"
@EOF = global i32 0
@.str.5 = [44 x i8] c"Error %c before offset %04X in input file.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([243 x i8], [243 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
br label %52
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %12, null
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %10
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %41
21: ; preds = %9
%22 = icmp eq i32* %15, null
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %13
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %38
27: ; preds = %21, %29
%28 = tail call i32 @record(i32* %12, i32* %15)
switch i32 %28, label %30 [
i32 57, label %29
i32 53, label %29
i32 49, label %29
i32 48, label %29
]
29: ; preds = %27, %27, %27, %27
br label %27
30: ; preds = %27
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %28, %31
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i64 @ftell(i32* %12)
%36 = trunc i64 %35 to i32
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %28, i32 %36)
br label %38
38: ; preds = %30, %33, %23
%39 = phi i32 [ undef, %23 ], [ %28, %33 ], [ %28, %30 ]
%40 = tail call i32 @fclose(i32* %12)
br label %41
41: ; preds = %17, %38
%42 = phi i32 [ undef, %17 ], [ %39, %38 ]
%43 = icmp eq i32* %15, null
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = tail call i32 @fclose(i32* %15)
br label %46
46: ; preds = %44, %41
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %42, %47
%49 = load i32, i32* @EXIT_SUCCESS
%50 = load i32, i32* @EXIT_FAILURE
%51 = select i1 %48, i32 %49, i32 %50
br label %52
52: ; preds = %46, %4
%53 = phi i32 [ %8, %4 ], [ %51, %46 ]
ret i32 %53
}