#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_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, unsigned char *, int);
void midi_prog_change(int p) {
  unsigned char b[2];
  int fd_out = open("/dev/midi", O_WRONLY);
  if (fd_out != -1) {
    b[0] = 0xc0;
    b[1] = p;
    write(fd_out, b, 2);
    close(fd_out);
  }
}


x86 assembly (clang, -O0):
<midi_prog_change>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     1180 <midi_prog_change+0x50>
movb   $0xc0,-0x6(%rbp)
mov    -0x4(%rbp),%eax
mov    %al,-0x5(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x6(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<midi_prog_change>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1179 <midi_prog_change+0x49>
mov    %eax,%ebx
movb   $0xc0,0x6(%rsp)
mov    %bpl,0x7(%rsp)
lea    0x6(%rsp),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/midi\00"
@O_WRONLY = global i32 0
define void @midi_prog_change(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 -64, i8* %10
%11 = load i32, i32* %2
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 %12, i8* %13
%14 = load i32, i32* %4
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%16 = call i32 @write(i32 %14, i8* %15, i32 2)
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %9, %1
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/midi\00"
@O_WRONLY = global i32 0
define void @midi_prog_change(i32 %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %12, label %7
7: ; preds = %1
store i8 -64, i8* %3
%8 = trunc i32 %0 to i8
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 %8, i8* %9
%10 = call i32 @write(i32 %5, i8* %3, i32 2)
%11 = tail call i32 @close(i32 %5)
br label %12
12: ; preds = %7, %1
ret void
}