#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*/ _IO(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd = open("/dev/ioctlS", O_RDWR);
  char buf[200];
  if (!fd) {
    printf("ERROR\n");
  }
  ioctl(fd, _IO((0x2F), 1), NULL);
  read(fd, buf, 10);
  ioctl(fd, _IO((0x2F), 2), NULL);
  write(fd, "Hi, Septem", 10);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11b7 <main+0x47>
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xe8(%rbp)
mov    $0x2f,%edi
mov    $0x1,%esi
call   1050 <_IO@plt>
mov    -0xe8(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xa,%edx
call   1080 <read@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xe4(%rbp)
mov    $0x2f,%edi
mov    $0x2,%esi
call   1050 <_IO@plt>
mov    -0xe4(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
lea    0xdec(%rip),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xd0,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    119f <main+0x2f>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2f,%edi
mov    $0x1,%esi
call   1050 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1080 <read@plt>
mov    $0x2f,%edi
mov    $0x2,%esi
call   1050 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
lea    0xe23(%rip),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/ioctlS\00"
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"ERROR\0A\00"
@.str.2 = [11 x i8] c"Hi, Septem\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [200 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %6
%16 = call i32 @_IO(i32 47, i32 1)
%17 = call i32 @ioctl(i32 %15, i32 %16, i32* null)
%18 = load i32, i32* %6
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 10)
%21 = load i32, i32* %6
%22 = call i32 @_IO(i32 47, i32 2)
%23 = call i32 @ioctl(i32 %21, i32 %22, i32* null)
%24 = load i32, i32* %6
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/ioctlS\00"
@O_RDWR = global i32 0
@.str.2 = [11 x i8] c"Hi, Septem\00"
@str = [6 x i8] c"ERROR\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [200 x i8]
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = icmp eq i32 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = tail call i32 @_IO(i32 47, i32 1)
%12 = tail call i32 @ioctl(i32 %5, i32 %11, i32* null)
%13 = call i32 @read(i32 %5, i8* %6, i32 10)
%14 = tail call i32 @_IO(i32 47, i32 2)
%15 = tail call i32 @ioctl(i32 %5, i32 %14, i32* null)
%16 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%17 = tail call i32 @close(i32 %5)
ret i32 0
}