#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*/ AUDIO_SELECT_SOURCE;
int atoi(char *);
int ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int audioSelectSource(int fd, char *arg) {
  int source;
  if (!arg)
    return -1;
  source = atoi(arg);
  if (ioctl(fd, AUDIO_SELECT_SOURCE, source) == -1)
    perror("AUDIO_SELECT_SOURCE");
  return 0;
}


x86 assembly (clang, -O0):
<audioSelectSource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <audioSelectSource+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <audioSelectSource+0x62>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    118b <audioSelectSource+0x5b>
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<audioSelectSource>:
push   %rbx
test   %rsi,%rsi
je     1167 <audioSelectSource+0x37>
mov    %edi,%ebx
mov    %rsi,%rdi
call   1050 <atoi@plt>
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <ioctl@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    116c <audioSelectSource+0x3c>
lea    0xea0(%rip),%rdi
call   1040 <perror@plt>
jmp    116c <audioSelectSource+0x3c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@AUDIO_SELECT_SOURCE = global i32 0
@.str = [20 x i8] c"AUDIO_SELECT_SOURCE\00"
define i32 @audioSelectSource(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 -1, i32* %3
br label %21
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = load i32, i32* @AUDIO_SELECT_SOURCE
%15 = load i32, i32* %6
%16 = call i32 @ioctl(i32 %13, i32 %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %10
store i32 0, i32* %3
br label %21
21: ; preds = %20, %9
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@AUDIO_SELECT_SOURCE = global i32 0
@.str = [20 x i8] c"AUDIO_SELECT_SOURCE\00"
define i32 @audioSelectSource(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = tail call i32 @atoi(i8* %1)
%6 = load i32, i32* @AUDIO_SELECT_SOURCE
%7 = tail call i32 @ioctl(i32 %0, i32 %6, i32 %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %4, %9, %2
%12 = phi i32 [ -1, %2 ], [ 0, %9 ], [ 0, %4 ]
ret i32 %12
}