#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_NONBLOCK;
int O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ play_file_video(int, int);
int /*<<< orphan*/ videoGetStatus(int);
int main(int argc, char **argv) {
  int fd;
  int filefd;
  if (argc < 2)
    return -1;
  if ((filefd = open(argv[1], O_RDONLY)) < 0) {
    perror("File open:");
    return -1;
  }
  if ((fd = open("/dev/dvb/adapter0/video0", O_RDWR | O_NONBLOCK)) < 0) {
    perror("VIDEO DEVICE: ");
    return -1;
  }
  videoGetStatus(fd);
  play_file_video(filefd, fd);
  close(fd);
  close(filefd);
  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)
cmpl   $0x2,-0x8(%rbp)
jge    117c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11b6 <main+0x66>
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <main+0xd2>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
lea    0xe3c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11f8 <main+0xa8>
lea    0xe3d(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <main+0xd2>
mov    -0x14(%rbp),%edi
call   1050 <videoGetStatus@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <play_file_video@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jl     11bd <main+0x6d>
mov    0x8(%rsi),%rdi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11c4 <main+0x74>
mov    %eax,%r14d
mov    0x2e6a(%rip),%rax
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11d2 <main+0x82>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <videoGetStatus@plt>
mov    %r14d,%edi
mov    %ebp,%esi
call   1030 <play_file_video@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe35(%rip),%rdi
call   1070 <perror@plt>
jmp    11bd <main+0x6d>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
jmp    11bd <main+0x6d>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [11 x i8] c"File open:\00"
@.str.1 = [25 x i8] c"/dev/dvb/adapter0/video0\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [15 x i8] c"VIDEO DEVICE: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %38
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
20: ; preds = %11
%21 = load i32, i32* @O_RDWR
%22 = load i32, i32* @O_NONBLOCK
%23 = or i32 %21, %22
%24 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %23)
store i32 %24, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
28: ; preds = %20
%29 = load i32, i32* %6
%30 = call i32 @videoGetStatus(i32 %29)
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = call i32 @play_file_video(i32 %31, i32 %32)
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %28, %26, %18, %10
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [11 x i8] c"File open:\00"
@.str.1 = [25 x i8] c"/dev/dvb/adapter0/video0\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [15 x i8] c"VIDEO DEVICE: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %25
12: ; preds = %4
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %14, %13
%16 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %25
20: ; preds = %12
%21 = tail call i32 @videoGetStatus(i32 %16)
%22 = tail call i32 @play_file_video(i32 %8, i32 %16)
%23 = tail call i32 @close(i32 %16)
%24 = tail call i32 @close(i32 %8)
br label %25
25: ; preds = %2, %20, %18, %10
%26 = phi i32 [ -1, %10 ], [ -1, %18 ], [ 0, %20 ], [ -1, %2 ]
ret i32 %26
}