#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
unsigned char SEQ_MIDIPUTC;
unsigned char atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long);
scalar_t__ write(int, unsigned char **, int);
int main(int argc, char *argv[]) {
  int fd;
  ssize_t res;
  unsigned char ev[4];
  fd = open("/dev/sequencer", O_RDWR);
  if (fd < 0) {
    perror("open ("
           "/dev/sequencer"
           ")");
    return EXIT_FAILURE;
  }
  ev[0] = SEQ_MIDIPUTC;
  ev[1] = 0xfe;
  ev[2] = argc > 1 ? atoi(argv[1]) : 0;
  res = write(fd, &ev, sizeof(ev));
  printf("end res = %li\n", (long)res);
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b5 <main+0x55>
lea    0xe70(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1230 <main+0xd0>
mov    0x2e3c(%rip),%rax
mov    (%rax),%al
mov    %al,-0x24(%rbp)
movb   $0xfe,-0x23(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11e7 <main+0x87>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
jmp    11f1 <main+0x91>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    11f1 <main+0x91>
mov    -0x28(%rbp),%eax
mov    %al,-0x22(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11e9 <main+0x89>
mov    %eax,%ebx
mov    0x2e69(%rip),%rax
mov    (%rax),%al
mov    %al,0xc(%rsp)
movb   $0xfe,0xd(%rsp)
cmp    $0x2,%ebp
jl     11aa <main+0x4a>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
jmp    11ac <main+0x4c>
xor    %eax,%eax
mov    %al,0xe(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xe5d(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dd4(%rip),%rax
jmp    11de <main+0x7e>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/sequencer\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"open (/dev/sequencer)\00"
@EXIT_FAILURE = global i32 0
@SEQ_MIDIPUTC = global i8 0
@.str.2 = [15 x i8] c"end res = %li\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %41
16: ; preds = %2
%17 = load i8, i8* @SEQ_MIDIPUTC
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
store i8 %17, i8* %18
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 -2, i8* %19
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call zeroext i8 @atoi(i8* %25)
%27 = zext i8 %26 to i32
br label %29
28: ; preds = %16
br label %29
29: ; preds = %28, %22
%30 = phi i32 [ %27, %22 ], [ 0, %28 ]
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
store i8 %31, i8* %32
%33 = load i32, i32* %6
%34 = bitcast [4 x i8]* %8 to i8**
%35 = call i64 @write(i32 %33, i8** %34, i32 4)
store i64 %35, i64* %7
%36 = load i64, i64* %7
%37 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %36)
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %3
br label %41
41: ; preds = %29, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/sequencer\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"open (/dev/sequencer)\00"
@EXIT_FAILURE = global i32 0
@SEQ_MIDIPUTC = global i8 0
@.str.2 = [15 x i8] c"end res = %li\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %25
10: ; preds = %2
%11 = load i8, i8* @SEQ_MIDIPUTC
store i8 %11, i8* %4
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 -2, i8* %12
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call zeroext i8 @atoi(i8* %16)
br label %18
18: ; preds = %10, %14
%19 = phi i8 [ %17, %14 ], [ 0, %10 ]
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
store i8 %19, i8* %20
%21 = bitcast [4 x i8]* %3 to i8**
%22 = call i64 @write(i32 %6, i8** %21, i32 4)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %22)
%24 = tail call i32 @close(i32 %6)
br label %25
25: ; preds = %18, %8
%26 = phi i32* [ @EXIT_FAILURE, %8 ], [ @EXIT_SUCCESS, %18 ]
%27 = load i32, i32* %26
ret i32 %27
}