#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 */
struct audio_mixer {
  int volume_left;
  int volume_right;
};
typedef int /*<<< orphan*/ mixer;

/* Variables and functions */
int /*<<< orphan*/ AUDIO_SET_MIXER;
int atoi(char *);
int ioctl(int, int /*<<< orphan*/, struct audio_mixer *);
int /*<<< orphan*/ memset(struct audio_mixer *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int audioSetVolume(int fd, char *arg) {
  int vol;
  struct audio_mixer mixer;
  if (!arg)
    return -1;
  vol = atoi(arg);
  memset(&mixer, 0, sizeof(mixer));
  mixer.volume_left = vol;
  mixer.volume_right = vol;
  if (ioctl(fd, AUDIO_SET_MIXER, &mixer) == -1)
    perror("AUDIO_SET_MIXER");
  return 0;
}


x86 assembly (clang, -O0):
<audioSetVolume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1166 <audioSetVolume+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <audioSetVolume+0x7f>
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11b8 <audioSetVolume+0x78>
lea    0xe4d(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<audioSetVolume>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     119a <audioSetVolume+0x5a>
mov    %edi,%ebp
mov    %rsi,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %rsp,%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    %ebx,(%rsp)
mov    %ebx,0x4(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11a0 <audioSetVolume+0x60>
lea    0xe6d(%rip),%rdi
call   1050 <perror@plt>
jmp    11a0 <audioSetVolume+0x60>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.audio_mixer = type { i32, i32 }
@AUDIO_SET_MIXER = global i32 0
@.str = [16 x i8] c"AUDIO_SET_MIXER\00"
define i32 @audioSetVolume(i32 %0, i8* %1) {
%3 = alloca %struct.audio_mixer
%4 = bitcast %struct.audio_mixer* %3 to i8*
%5 = icmp eq i8* %1, null
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i32 @atoi(i8* %1)
%8 = call i32 @memset(%struct.audio_mixer* %3, i32 0, i32 8)
%9 = getelementptr inbounds %struct.audio_mixer, %struct.audio_mixer* %3, i64 0, i32 0
store i32 %7, i32* %9
%10 = getelementptr inbounds %struct.audio_mixer, %struct.audio_mixer* %3, i64 0, i32 1
store i32 %7, i32* %10
%11 = load i32, i32* @AUDIO_SET_MIXER
%12 = call i32 @ioctl(i32 %0, i32 %11, %struct.audio_mixer* %3)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %6, %14, %2
%17 = phi i32 [ -1, %2 ], [ 0, %14 ], [ 0, %6 ]
ret i32 %17
}