#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_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int fd = open("/dev/hwm1", O_RDONLY);
  if (fd == -1) {
    printf("Error opening device file\n");
    return -1;
  }
  ioctl(fd, 0xff01);
  ioctl(fd, 0xff00);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1190 <main+0x50>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <main+0x79>
mov    -0x14(%rbp),%edi
mov    $0xff01,%esi
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0xff00,%esi
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1180 <main+0x40>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0xff01,%esi
call   1040 <ioctl@plt>
mov    %ebx,%edi
mov    $0xff00,%esi
call   1040 <ioctl@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/hwm1\00"
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"Error opening device file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %20
13: ; preds = %2
%14 = load i32, i32* %6
%15 = call i32 @ioctl(i32 %14, i32 65281)
%16 = load i32, i32* %6
%17 = call i32 @ioctl(i32 %16, i32 65280)
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
store i32 0, i32* %3
br label %20
20: ; preds = %13, %11
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/hwm1\00"
@O_RDONLY = global i32 0
@str = [26 x i8] c"Error opening device file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %12
8: ; preds = %2
%9 = tail call i32 @ioctl(i32 %4, i32 65281)
%10 = tail call i32 @ioctl(i32 %4, i32 65280)
%11 = tail call i32 @close(i32 %4)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %13
}