#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char);
int scanf(char *, char *);
int srec_read(char *, char *);
int /*<<< orphan*/ stderr;
char *stripwhite(char *);
int main(int argc, char **argv) {
  char *name, *s;
  char image[131072];
  int val, ret;
  int i;
  if (argc == 2)
    name = argv[1];
  else {
    name = (char *)malloc(128 * sizeof(char));
    fprintf(stderr, "Enter name of S-Record file: ");
    ret = scanf("%s", name);
  }
  s = stripwhite(name);
  val = srec_read(s, image);
  if (val == -1) {
    fprintf(stderr, "Did not load file...\n");
    return -1;
  }
  fprintf(stderr, "screc read, image is %d bytes!\n", val);
  for (i = 0; i < val; i++) {
    printf("%c", image[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1194 <main+0x34>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11cf <main+0x6f>
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1080 <scanf@plt>
mov    %eax,-0x20028(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <stripwhite@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x20020(%rbp),%rsi
call   1030 <srec_read@plt>
mov    %eax,-0x20024(%rbp)
cmpl   $0xffffffff,-0x20024(%rbp)
jne    1222 <main+0xc2>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128a <main+0x12a>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    -0x20024(%rbp),%edx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2002c(%rbp)
mov    -0x2002c(%rbp),%eax
cmp    -0x20024(%rbp),%eax
jge    128a <main+0x12a>
movslq -0x2002c(%rbp),%rax
lea    0xdee(%rip),%rdi
movsbl -0x20020(%rbp,%rax,1),%esi
ff
call   1040 <printf@plt>
mov    -0x2002c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2002c(%rbp)
jmp    1249 <main+0xe9>
mov    -0x4(%rbp),%eax
add    $0x20030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x20008,%rsp
cmp    $0x2,%edi
jne    1178 <main+0x18>
mov    0x8(%rsi),%rbx
jmp    11ab <main+0x4b>
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1070 <stripwhite@plt>
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <srec_read@plt>
mov    %eax,%ebp
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
cmp    $0xffffffff,%ebp
je     1217 <main+0xb7>
lea    0xe62(%rip),%rsi
xor    %r14d,%r14d
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %ebp,%ebp
jle    122b <main+0xcb>
mov    %ebp,%ebx
xor    %r14d,%r14d
lea    0xe66(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rsp,%rbp,1),%esi
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1200 <main+0xa0>
jmp    122b <main+0xcb>
lea    0xe03(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x20008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Enter name of S-Record file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"Did not load file...\0A\00"
@.str.3 = [32 x i8] c"screc read, image is %d bytes!\0A\00"
@.str.4 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [131072 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
br label %25
18: ; preds = %2
%19 = call i64 @malloc(i32 128)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %6
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 %24, i32* %10
br label %25
25: ; preds = %18, %14
%26 = load i8*, i8** %6
%27 = call i8* @stripwhite(i8* %26)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = getelementptr inbounds [131072 x i8], [131072 x i8]* %8, i64 0, i64 0
%30 = call i32 @srec_read(i8* %28, i8* %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %53
36: ; preds = %25
%37 = load i32, i32* @stderr
%38 = load i32, i32* %9
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %38)
store i32 0, i32* %11
br label %40
40: ; preds = %50, %36
%41 = load i32, i32* %11
%42 = load i32, i32* %9
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [131072 x i8], [131072 x i8]* %8, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8 signext %48)
br label %50
50: ; preds = %44
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %40
53: ; preds = %33, %40
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Enter name of S-Record file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"Did not load file...\0A\00"
@.str.3 = [32 x i8] c"screc read, image is %d bytes!\0A\00"
@.str.4 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [131072 x i8]
%4 = getelementptr inbounds [131072 x i8], [131072 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %15
9: ; preds = %2
%10 = tail call i64 @malloc(i32 128)
%11 = inttoptr i64 %10 to i8*
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %15
15: ; preds = %9, %6
%16 = phi i8* [ %8, %6 ], [ %11, %9 ]
%17 = tail call i8* @stripwhite(i8* %16)
%18 = call i32 @srec_read(i8* %17, i8* %4)
%19 = icmp eq i32 %18, -1
%20 = load i32, i32* @stderr
br i1 %19, label %21, label %23
21: ; preds = %15
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %35
23: ; preds = %15
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%25 = icmp sgt i32 %18, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = zext i32 %18 to i64
br label %28
28: ; preds = %26, %28
%29 = phi i64 [ 0, %26 ], [ %33, %28 ]
%30 = getelementptr inbounds [131072 x i8], [131072 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8 signext %31)
%33 = add nuw nsw i64 %29, 1
%34 = icmp eq i64 %33, %27
br i1 %34, label %35, label %28
35: ; preds = %28, %23, %21
%36 = phi i32 [ -1, %21 ], [ 0, %23 ], [ 0, %28 ]
ret i32 %36
}