#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 ioctl(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int fd;
  int i;
  char data[256];
  int retval;
  fd = open("/dev/gatieme", O_RDWR);
  if (fd == -1) {
    perror("error open");
    exit(-1);
  }
  printf("open "
         "/dev/gatieme"
         " successfully\n");
  retval = ioctl(fd, 1, 0);
  if (retval == -1) {
    perror("ioctl error");
    exit(-1);
  }
  printf("send command1 successfully\n");
  retval = ioctl(fd, 2, 0);
  if (retval == -1) {
    perror("ioctl error");
    exit(-1);
  }
  printf("send command2 successfully\n");
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11a3 <main+0x43>
lea    0xe79(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    11e7 <main+0x87>
lea    0xe60(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    122b <main+0xcb>
lea    0xe1c(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11db <main+0x7b>
mov    %eax,%ebx
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11d2 <main+0x72>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11d2 <main+0x72>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe3f(%rip),%rdi
jmp    11e2 <main+0x82>
lea    0xe2b(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/gatieme\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"error open\00"
@.str.2 = [32 x i8] c"open /dev/gatieme successfully\0A\00"
@.str.3 = [12 x i8] c"ioctl error\00"
@.str.4 = [28 x i8] c"send command1 successfully\0A\00"
@.str.5 = [28 x i8] c"send command2 successfully\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* %1
%15 = call i32 @ioctl(i32 %14, i32 1, i32 0)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %12
%22 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* %1
%24 = call i32 @ioctl(i32 %23, i32 2, i32 0)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %21
%31 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%32 = load i32, i32* %1
%33 = call i32 @close(i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/gatieme\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"error open\00"
@.str.3 = [12 x i8] c"ioctl error\00"
@str = [31 x i8] c"open /dev/gatieme successfully\00"
@str.6 = [27 x i8] c"send command1 successfully\00"
@str.7 = [27 x i8] c"send command2 successfully\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @ioctl(i32 %2, i32 1, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%16 = tail call i32 @ioctl(i32 %2, i32 2, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %14
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
%23 = tail call i32 @close(i32 %2)
ret i32 0
}