#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ send_bcl(int, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char *midi_device = "/dev/midi1";
  if (argc > 1) {
    midi_device = argv[1];
  }
  int seqfd = open(midi_device, O_RDWR);
  if (seqfd == -1) {
    printf("Error: cannot open %s\n", "/dev/midi1");
    exit(1);
  }
  if (argc > 2) {
    if (strcmp(argv[2], "bcl_send") == 0)
      send_bcl(seqfd, argv[3]);
  }
  close(seqfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1197 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11d3 <main+0x73>
lea    0xe4e(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1210 <main+0xb0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe36(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    120b <main+0xab>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1060 <send_bcl@plt>
jmp    1210 <main+0xb0>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
cmp    $0x2,%edi
jl     1174 <main+0x14>
mov    0x8(%r14),%rdi
jmp    117b <main+0x1b>
lea    0xe85(%rip),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11c3 <main+0x63>
mov    %eax,%ebp
cmp    $0x3,%ebx
jl     11b5 <main+0x55>
mov    0x10(%r14),%rdi
lea    0xe82(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b5 <main+0x55>
mov    0x18(%r14),%rsi
mov    %ebp,%edi
call   1060 <send_bcl@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe41(%rip),%rdi
lea    0xe2f(%rip),%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/midi1\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Error: cannot open %s\0A\00"
@.str.2 = [9 x i8] c"bcl_send\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
br label %14
14: ; preds = %10, %2
%15 = load i8*, i8** %6
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load i32, i32* %7
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @send_bcl(i32 %33, i8* %36)
br label %38
38: ; preds = %32, %26
br label %39
39: ; preds = %38, %23
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/midi1\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Error: cannot open %s\0A\00"
@.str.2 = [9 x i8] c"bcl_send\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
br label %7
7: ; preds = %4, %2
%8 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = icmp sgt i32 %0, 2
br i1 %16, label %17, label %26
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @send_bcl(i32 %10, i8* %24)
br label %26
26: ; preds = %17, %22, %15
%27 = tail call i32 @close(i32 %10)
ret i32 0
}