#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*/ cam_conf_set_camera_fd(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int camera_open_dev() {
  int camera_fd = -1;
  cam_conf_set_camera_fd(-1);
  camera_fd = open("/dev/video0", O_RDWR);
  if (camera_fd < 0) {
    printf("open dev error\n");
    return -1;
  }
  cam_conf_set_camera_fd(camera_fd);
  return 0;
}


x86 assembly (clang, -O0):
<camera_open_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
mov    $0xffffffff,%edi
call   1030 <cam_conf_set_camera_fd@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1183 <camera_open_dev+0x53>
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <camera_open_dev+0x62>
mov    -0x8(%rbp),%edi
call   1030 <cam_conf_set_camera_fd@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<camera_open_dev>:
push   %rbx
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edi
call   1040 <cam_conf_set_camera_fd@plt>
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    0xeb0(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1164 <camera_open_dev+0x34>
mov    %eax,%edi
call   1040 <cam_conf_set_camera_fd@plt>
xor    %ebx,%ebx
jmp    1170 <camera_open_dev+0x40>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/video0\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"open dev error\0A\00"
define i32 @camera_open_dev() {
%1 = alloca i32
%2 = alloca i32
store i32 -1, i32* %2
%3 = call i32 @cam_conf_set_camera_fd(i32 -1)
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %13
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 @cam_conf_set_camera_fd(i32 %11)
store i32 0, i32* %1
br label %13
13: ; preds = %10, %8
%14 = load i32, i32* %1
ret i32 %14
}

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