#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*/ _IO(int /*<<< orphan*/, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  char *file_name = "/dev/new_midi";
  int fd;
  fd = open(file_name, 0);
  if (fd == -1) {
    perror("new_midi open");
    return 2;
  }
  ioctl(fd, _IO(0, 1));
  close(fd);
  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    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a1 <main+0x51>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    11cc <main+0x7c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     118f <main+0x3f>
mov    %eax,%ebp
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe78(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%ebx
jmp    1186 <main+0x36>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/new_midi\00"
@.str.1 = [14 x i8] c"new_midi open\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 ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @open(i8* %8, i32 0)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %20
14: ; preds = %2
%15 = load i32, i32* %7
%16 = call i32 @_IO(i32 0, i32 1)
%17 = call i32 @ioctl(i32 %15, i32 %16)
%18 = load i32, i32* %7
%19 = call i32 @close(i32 %18)
store i32 0, i32* %3
br label %20
20: ; preds = %14, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/new_midi\00"
@.str.1 = [14 x i8] c"new_midi open\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %11
7: ; preds = %2
%8 = tail call i32 @_IO(i32 0, i32 1)
%9 = tail call i32 @ioctl(i32 %3, i32 %8)
%10 = tail call i32 @close(i32 %3)
br label %11
11: ; preds = %7, %5
%12 = phi i32 [ 2, %5 ], [ 0, %7 ]
ret i32 %12
}