#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 /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
unsigned char *load_sysex(char filename[]) {
  FILE *syxfile;
  unsigned char *data;
  if (strcmp(filename, "-") == 0)
    syxfile = stdin;
  else
    syxfile = fopen(filename, "r");
  if (syxfile == NULL) {
    perror("load_sysex: fopen:");
    return NULL;
  }
  data = malloc(sizeof(unsigned char) * 297);
  if (data == NULL) {
    perror("load_sysex: malloc:");
    return NULL;
  }
  if (fread(data, sizeof(unsigned char), 297, syxfile) != 297) {
    fputs("load_sysex: fread: short read\n", stderr);
    free(data);
    return NULL;
  }
  if ((data[0] != 0xF0) || (data[1] != 0x42) || ((data[2] & 0xF0) != 0x30) ||
      (data[3] != 0x58) || (data[4] != 0x40)) {
    fputs("load_sysex: not a microkorg program dump\n", stderr);
    free(data);
    return 0;
  }
  return data;
}


x86 assembly (clang, -O0):
<load_sysex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11a9 <load_sysex+0x39>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11bd <load_sysex+0x4d>
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e1 <load_sysex+0x71>
lea    0xe35(%rip),%rdi
call   1090 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ee <load_sysex+0x17e>
mov    $0x129,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1213 <load_sysex+0xa3>
lea    0xe16(%rip),%rdi
call   1090 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ee <load_sysex+0x17e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x129,%edx
call   1040 <fread@plt>
cmp    $0x129,%eax
je     1260 <load_sysex+0xf0>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
lea    0xde6(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ee <load_sysex+0x17e>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xf0,%eax
jne    12bb <load_sysex+0x14b>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x42,%eax
jne    12bb <load_sysex+0x14b>
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xf0,%eax
cmp    $0x30,%eax
jne    12bb <load_sysex+0x14b>
mov    -0x20(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0x58,%eax
jne    12bb <load_sysex+0x14b>
mov    -0x20(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x40,%eax
je     12e6 <load_sysex+0x176>
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
lea    0xd7f(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ee <load_sysex+0x17e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_sysex>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe82(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1235 <load_sysex+0xc5>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %r14,%r14
je     1248 <load_sysex+0xd8>
mov    $0x129,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1256 <load_sysex+0xe6>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x129,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    $0x129,%eax
jne    120b <load_sysex+0x9b>
cmpb   $0xf0,(%rbx)
jne    11f9 <load_sysex+0x89>
cmpb   $0x42,0x1(%rbx)
jne    11f9 <load_sysex+0x89>
mov    0x2(%rbx),%al
and    $0xf0,%al
cmp    $0x30,%al
jne    11f9 <load_sysex+0x89>
cmpb   $0x58,0x3(%rbx)
jne    11f9 <load_sysex+0x89>
cmpb   $0x40,0x4(%rbx)
je     122a <load_sysex+0xba>
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
jmp    121b <load_sysex+0xab>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    0xe10(%rip),%rdi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dac(%rip),%rax
mov    (%rax),%r14
test   %r14,%r14
jne    11a7 <load_sysex+0x37>
lea    0xdb5(%rip),%rdi
call   1090 <perror@plt>
jmp    1228 <load_sysex+0xb8>
lea    0xdba(%rip),%rdi
call   1090 <perror@plt>
jmp    1228 <load_sysex+0xb8>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"load_sysex: fopen:\00"
@.str.3 = [20 x i8] c"load_sysex: malloc:\00"
@.str.4 = [31 x i8] c"load_sysex: fread: short read\0A\00"
@stderr = global i32 0
@.str.5 = [42 x i8] c"load_sysex: not a microkorg program dump\0A\00"
define i8* @load_sysex(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32*, i32** @stdin
store i32* %10, i32** %4
br label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %4
br label %14
14: ; preds = %11, %9
%15 = load i32*, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %73
19: ; preds = %14
%20 = call i8* @malloc(i32 297)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %73
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i32*, i32** %4
%28 = call i32 @fread(i8* %26, i32 1, i32 297, i32* %27)
%29 = icmp ne i32 %28, 297
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %5
%34 = call i32 @free(i8* %33)
store i8* null, i8** %2
br label %73
35: ; preds = %25
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = icmp ne i32 %39, 240
br i1 %40, label %66, label %41
41: ; preds = %35
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp ne i32 %45, 66
br i1 %46, label %66, label %47
47: ; preds = %41
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 2
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = and i32 %51, 240
%53 = icmp ne i32 %52, 48
br i1 %53, label %66, label %54
54: ; preds = %47
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i64 3
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = icmp ne i32 %58, 88
br i1 %59, label %66, label %60
60: ; preds = %54
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i64 4
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = icmp ne i32 %64, 64
br i1 %65, label %66, label %71
66: ; preds = %60, %54, %47, %41, %35
%67 = load i32, i32* @stderr
%68 = call i32 @fputs(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%69 = load i8*, i8** %5
%70 = call i32 @free(i8* %69)
store i8* null, i8** %2
br label %73
71: ; preds = %60
%72 = load i8*, i8** %5
store i8* %72, i8** %2
br label %73
73: ; preds = %71, %66, %30, %23, %17
%74 = load i8*, i8** %2
ret i8* %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"load_sysex: fopen:\00"
@.str.3 = [20 x i8] c"load_sysex: malloc:\00"
@.str.4 = [31 x i8] c"load_sysex: fread: short read\0A\00"
@stderr = global i32 0
@.str.5 = [42 x i8] c"load_sysex: not a microkorg program dump\0A\00"
define noalias i8* @load_sysex(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32*, i32** @stdin
br label %8
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = phi i32* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %49
13: ; preds = %8
%14 = tail call dereferenceable_or_null(297) i8* @malloc(i32 297)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %49
18: ; preds = %13
%19 = tail call i32 @fread(i8* %14, i32 1, i32 297, i32* %9)
%20 = icmp eq i32 %19, 297
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = tail call i32 @free(i8* %14)
br label %49
25: ; preds = %18
%26 = load i8, i8* %14
%27 = icmp eq i8 %26, -16
br i1 %27, label %28, label %45
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %14, i64 1
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 66
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = getelementptr inbounds i8, i8* %14, i64 2
%34 = load i8, i8* %33
%35 = and i8 %34, -16
%36 = icmp eq i8 %35, 48
br i1 %36, label %37, label %45
37: ; preds = %32
%38 = getelementptr inbounds i8, i8* %14, i64 3
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 88
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = getelementptr inbounds i8, i8* %14, i64 4
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 64
br i1 %44, label %49, label %45
45: ; preds = %41, %37, %32, %28, %25
%46 = load i32, i32* @stderr
%47 = tail call i32 @fputs(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%48 = tail call i32 @free(i8* %14)
br label %49
49: ; preds = %41, %45, %21, %16, %11
%50 = phi i8* [ null, %11 ], [ null, %16 ], [ null, %21 ], [ null, %45 ], [ %14, %41 ]
ret i8* %50
}