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


x86 assembly (clang, -O0):
<dvbaudio_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2ebb(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe96(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1030 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11b8 <dvbaudio_open+0x98>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe7d(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1030 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvbaudio_open>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2eb8(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <sprintf@plt>
mov    0x2e76(%rip),%r12
mov    (%r12),%esi
mov    %rbx,%rdi
call   1030 <open@plt>
test   %eax,%eax
jns    119b <dvbaudio_open+0x7b>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <sprintf@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
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
@.str = [27 x i8] c"/dev/dvb/adapter%i/audio%i\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"/dev/dvb%i.audio%i\00"
define i32 @dvbaudio_open(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* @PATH_MAX
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %12, i32 %16)
store i32 %17, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* @O_RDWR
%24 = call i32 @open(i8* %12, i32 %23)
store i32 %24, i32* %7
br label %25
25: ; preds = %19, %2
%26 = load i32, i32* %7
%27 = load i8*, i8** %5
ret i32 %26
}

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