#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 const *, int);
int /*<<< orphan*/ printf(char *, char const *);
int tcc_video_scaler_open(const char *dev_name) {
  int fd = -1;
  if (dev_name != NULL) {
    fd = open(dev_name, O_RDWR | O_NDELAY);
    if (fd >= 0) {
      printf("%s open succeed\n", dev_name);
    } else
      printf("can't open %s\n", dev_name);
  }
  return fd;
}


x86 assembly (clang, -O0):
<tcc_video_scaler_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1190 <tcc_video_scaler_open+0x70>
mov    -0x8(%rbp),%rdi
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    0x2e86(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     117b <tcc_video_scaler_open+0x5b>
mov    -0x8(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
jmp    118b <tcc_video_scaler_open+0x6b>
mov    -0x8(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
jmp    1190 <tcc_video_scaler_open+0x70>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcc_video_scaler_open>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1162 <tcc_video_scaler_open+0x42>
mov    %rdi,%rbx
mov    0x2eb6(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
lea    0xeb3(%rip),%rax
lea    0xebd(%rip),%rdi
cmovns %rax,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    1167 <tcc_video_scaler_open+0x47>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str = [17 x i8] c"%s open succeed\0A\00"
@.str.1 = [15 x i8] c"can't open %s\0A\00"
define i32 @tcc_video_scaler_open(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %21
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NDELAY
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %7, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %20
17: ; preds = %6
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %14
br label %21
21: ; preds = %20, %1
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str = [17 x i8] c"%s open succeed\0A\00"
@.str.1 = [15 x i8] c"can't open %s\0A\00"
define i32 @tcc_video_scaler_open(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NDELAY
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp sgt i32 %7, -1
%9 = select i1 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0)
%10 = tail call i32 @printf(i8* %9, i8* %0)
br label %11
11: ; preds = %3, %1
%12 = phi i32 [ -1, %1 ], [ %7, %3 ]
ret i32 %12
}