#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int save_sysex(unsigned char *data, char filename[]) {
  FILE *syxfile;
  if (strcmp(filename, "-") == 0)
    syxfile = stdout;
  else
    syxfile = fopen(filename, "w");
  if (syxfile == NULL) {
    perror("save_sysex: fopen:");
    return 0;
  }
  if (fwrite(data, sizeof(unsigned char), 297, syxfile) != 297) {
    perror("save_sysex: fwrite:");
    return 0;
  }
  fclose(syxfile);
  return 1;
}


x86 assembly (clang, -O0):
<save_sysex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    118d <save_sysex+0x3d>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11a1 <save_sysex+0x51>
mov    -0x18(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c4 <save_sysex+0x74>
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    120e <save_sysex+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x129,%edx
call   1070 <fwrite@plt>
cmp    $0x129,%eax
je     11fe <save_sysex+0xae>
lea    0xe2a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    120e <save_sysex+0xbe>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_sysex>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b5 <save_sysex+0x65>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     11c4 <save_sysex+0x74>
mov    $0x1,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x129,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    $0x129,%eax
jne    11cd <save_sysex+0x7d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e24(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    1185 <save_sysex+0x35>
lea    0xe39(%rip),%rdi
jmp    11d4 <save_sysex+0x84>
lea    0xe43(%rip),%rdi
call   1060 <perror@plt>
xor    %ebp,%ebp
jmp    11ae <save_sysex+0x5e>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"save_sysex: fopen:\00"
@.str.3 = [20 x i8] c"save_sysex: fwrite:\00"
define i32 @save_sysex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32*, i32** @stdout
store i32* %11, i32** %6
br label %15
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
br label %15
15: ; preds = %12, %10
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %30
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i32*, i32** %6
%23 = call i32 @fwrite(i8* %21, i32 1, i32 297, i32* %22)
%24 = icmp ne i32 %23, 297
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %30
27: ; preds = %20
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
store i32 1, i32* %3
br label %30
30: ; preds = %27, %25, %18
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"save_sysex: fopen:\00"
@.str.3 = [20 x i8] c"save_sysex: fwrite:\00"
define i32 @save_sysex(i8* nocapture %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load i32*, i32** @stdout
br label %9
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %5
%10 = phi i32* [ %6, %5 ], [ %8, %7 ]
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %21
14: ; preds = %9
%15 = tail call i32 @fwrite(i8* %0, i32 1, i32 297, i32* %10)
%16 = icmp eq i32 %15, 297
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %21
19: ; preds = %14
%20 = tail call i32 @fclose(i32* %10)
br label %21
21: ; preds = %19, %17, %12
%22 = phi i32 [ 0, %12 ], [ 0, %17 ], [ 1, %19 ]
ret i32 %22
}