#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 O_NDELAY;
int O_RDWR;
int open(char *, int);
int /*<<< orphan*/ printf(char *, int);
int mtv_drv_open(void **hDevice) {
  int handle;
  handle = open("/dev/isdbt", O_RDWR | O_NDELAY);
  if (handle < 0) {
    printf("Cannot open handle : %d\n", handle);
    return 1;
  }
  *hDevice = handle;
  return 0;
}


x86 assembly (clang, -O0):
<mtv_drv_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%esi
mov    0x2e9c(%rip),%rax
or     (%rax),%esi
lea    0xebb(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1172 <mtv_drv_open+0x52>
mov    -0x14(%rbp),%esi
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1184 <mtv_drv_open+0x64>
movslq -0x14(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtv_drv_open>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ebd(%rip),%rax
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xec3(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     114f <mtv_drv_open+0x2f>
mov    %eax,%eax
mov    %rax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret
lea    0xeb5(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/isdbt\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [25 x i8] c"Cannot open handle : %d\0A\00"
define i32 @mtv_drv_open(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %3
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 1, i32* %2
br label %19
14: ; preds = %1
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = load i8**, i8*** %3
store i8* %17, i8** %18
store i32 0, i32* %2
br label %19
19: ; preds = %14, %11
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/isdbt\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [25 x i8] c"Cannot open handle : %d\0A\00"
define i32 @mtv_drv_open(i8** nocapture writeonly %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NDELAY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %12
9: ; preds = %1
%10 = zext i32 %5 to i64
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %0
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %13
}