#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_RDWR;
int /*<<< orphan*/ PATH_MAX;
int open(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int dvbdemux_open_demux(int adapter, int demuxdevice, int nonblocking) {
  char filename[PATH_MAX + 1];
  int flags = O_RDWR;
  int fd;
  if (nonblocking)
    flags |= O_NONBLOCK;
  sprintf(filename, "/dev/dvb/adapter%i/demux%i", adapter, demuxdevice);
  if ((fd = open(filename, flags)) < 0) {
    sprintf(filename, "/dev/dvb%i.demux%i", adapter, demuxdevice);
    fd = open(filename, flags);
  }
  return fd;
}


x86 assembly (clang, -O0):
<dvbdemux_open_demux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    0x2eb8(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1185 <dvbdemux_open_demux+0x65>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe6a(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    11d8 <dvbdemux_open_demux+0xb8>
mov    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe57(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <open@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvbdemux_open_demux>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e88(%rip),%rax
test   %edx,%edx
je     1166 <dvbdemux_open_demux+0x46>
mov    0x2e75(%rip),%rcx
mov    (%rcx),%r12d
or     (%rax),%r12d
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <open@plt>
test   %eax,%eax
jns    11ad <dvbdemux_open_demux+0x8d>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <open@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str = [27 x i8] c"/dev/dvb/adapter%i/demux%i\00"
@.str.1 = [19 x i8] c"/dev/dvb%i.demux%i\00"
define i32 @dvbdemux_open_demux(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = load i32, i32* @O_RDWR
store i32 %16, i32* %9
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @O_NONBLOCK
%21 = load i32, i32* %9
%22 = or i32 %21, %20
store i32 %22, i32* %9
br label %23
23: ; preds = %19, %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32, i32* %9
%28 = call i32 @open(i8* %15, i32 %27)
store i32 %28, i32* %10
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %23
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32)
%34 = load i32, i32* %9
%35 = call i32 @open(i8* %15, i32 %34)
store i32 %35, i32* %10
br label %36
36: ; preds = %30, %23
%37 = load i32, i32* %10
%38 = load i8*, i8** %7
ret i32 %37
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str = [27 x i8] c"/dev/dvb/adapter%i/demux%i\00"
@.str.1 = [19 x i8] c"/dev/dvb%i.demux%i\00"
define i32 @dvbdemux_open_demux(i32 %0, i32 %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i32, i32* @O_RDWR
%9 = icmp eq i32 %2, 0
%10 = load i32, i32* @O_NONBLOCK
%11 = select i1 %9, i32 0, i32 %10
%12 = or i32 %11, %8
%13 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%14 = call i32 @open(i8* %7, i32 %12)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1)
%18 = call i32 @open(i8* %7, i32 %12)
br label %19
19: ; preds = %16, %3
%20 = phi i32 [ %18, %16 ], [ %14, %3 ]
ret i32 %20
}