#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(char, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int fd;
  fd = open("/dev/tanglinux", O_RDWR);
  if (fd < 0) {
    printf("can't open /dev/tanglinux\n");
    return -1;
  }
  ioctl(fd, _IO('T', 1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1189 <main+0x49>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <main+0x6f>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x54,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1178 <main+0x38>
mov    %eax,%ebx
mov    $0x54,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/tanglinux\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"can't open /dev/tanglinux\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %13
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @_IO(i8 signext 84, i32 1)
%12 = call i32 @ioctl(i32 %10, i32 %11)
store i32 0, i32* %1
br label %13
13: ; preds = %9, %7
%14 = load i32, i32* %1
ret i32 %14
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/tanglinux\00"
@O_RDWR = global i32 0
@str = [26 x i8] c"can't open /dev/tanglinux\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %9
6: ; preds = %0
%7 = tail call i32 @_IO(i8 signext 84, i32 1)
%8 = tail call i32 @ioctl(i32 %2, i32 %7)
br label %9
9: ; preds = %6, %4
%10 = phi i32 [ -1, %4 ], [ 0, %6 ]
ret i32 %10
}