#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_WRONLY;
int SOUND_MASK_PCM;
int SOUND_MASK_VOLUME;
int SOUND_MIXER_DEVMASK;
int SOUND_MIXER_WRITE_PCM;
int SOUND_MIXER_WRITE_VOLUME;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, int *);
int open(char *, int /*<<< orphan*/);
void set_volume(int l, int r) {
  int fd, v, cmd, devs;
  ;
  fd = open("/dev/mixer", O_WRONLY);
  if (fd == -1) {
    ;
    return;
  }
  ioctl(fd, SOUND_MIXER_DEVMASK, &devs);
  if (devs & SOUND_MASK_PCM) {
    cmd = SOUND_MIXER_WRITE_PCM;
  } else if (devs & SOUND_MASK_VOLUME) {
    cmd = SOUND_MIXER_WRITE_VOLUME;
  } else {
    close(fd);
    return;
  }
  v = (r << 8) | l;
  ioctl(fd, cmd, &v);
  close(fd);
}


x86 assembly (clang, -O0):
<set_volume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xeb2(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1165 <set_volume+0x35>
jmp    11fb <set_volume+0xcb>
mov    -0xc(%rbp),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x18(%rbp),%eax
mov    0x2e44(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a0 <set_volume+0x70>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <set_volume+0xa8>
mov    -0x18(%rbp),%eax
mov    0x2e3e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11c6 <set_volume+0x96>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11d3 <set_volume+0xa3>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
jmp    11fb <set_volume+0xcb>
jmp    11d8 <set_volume+0xa8>
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_volume>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xeb3(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11b7 <set_volume+0x87>
mov    %eax,%ebx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    0x8(%rsp),%eax
mov    0x2e4f(%rip),%rcx
test   %eax,(%rcx)
je     1186 <set_volume+0x56>
mov    0x2e54(%rip),%rax
jmp    1198 <set_volume+0x68>
mov    0x2e5b(%rip),%rcx
test   %eax,(%rcx)
je     11b0 <set_volume+0x80>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
shl    $0x8,%ebp
or     %r14d,%ebp
mov    %ebp,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/mixer\00"
@O_WRONLY = global i32 0
@SOUND_MIXER_DEVMASK = global i32 0
@SOUND_MASK_PCM = global i32 0
@SOUND_MIXER_WRITE_PCM = global i32 0
@SOUND_MASK_VOLUME = global i32 0
@SOUND_MIXER_WRITE_VOLUME = global i32 0
define void @set_volume(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
br label %45
14: ; preds = %2
%15 = load i32, i32* %5
%16 = load i32, i32* @SOUND_MIXER_DEVMASK
%17 = call i32 @ioctl(i32 %15, i32 %16, i32* %8)
%18 = load i32, i32* %8
%19 = load i32, i32* @SOUND_MASK_PCM
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = load i32, i32* @SOUND_MIXER_WRITE_PCM
store i32 %23, i32* %7
br label %35
24: ; preds = %14
%25 = load i32, i32* %8
%26 = load i32, i32* @SOUND_MASK_VOLUME
%27 = and i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* @SOUND_MIXER_WRITE_VOLUME
store i32 %30, i32* %7
br label %34
31: ; preds = %24
%32 = load i32, i32* %5
%33 = call i32 @close(i32 %32)
br label %45
34: ; preds = %29
br label %35
35: ; preds = %34, %22
%36 = load i32, i32* %4
%37 = shl i32 %36, 8
%38 = load i32, i32* %3
%39 = or i32 %37, %38
store i32 %39, i32* %6
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = call i32 @ioctl(i32 %40, i32 %41, i32* %6)
%43 = load i32, i32* %5
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %35, %31, %13
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/mixer\00"
@O_WRONLY = global i32 0
@SOUND_MIXER_DEVMASK = global i32 0
@SOUND_MASK_PCM = global i32 0
@SOUND_MIXER_WRITE_PCM = global i32 0
@SOUND_MASK_VOLUME = global i32 0
@SOUND_MIXER_WRITE_VOLUME = global i32 0
define void @set_volume(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %29, label %10
10: ; preds = %2
%11 = load i32, i32* @SOUND_MIXER_DEVMASK
%12 = call i32 @ioctl(i32 %8, i32 %11, i32* %4)
%13 = load i32, i32* %4
%14 = load i32, i32* @SOUND_MASK_PCM
%15 = and i32 %14, %13
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* @SOUND_MASK_VOLUME
%19 = and i32 %18, %13
%20 = icmp eq i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %17, %10
%22 = phi i32* [ @SOUND_MIXER_WRITE_PCM, %10 ], [ @SOUND_MIXER_WRITE_VOLUME, %17 ]
%23 = load i32, i32* %22
%24 = shl i32 %1, 8
%25 = or i32 %24, %0
store i32 %25, i32* %3
%26 = call i32 @ioctl(i32 %8, i32 %23, i32* %3)
br label %27
27: ; preds = %17, %21
%28 = call i32 @close(i32 %8)
br label %29
29: ; preds = %27, %2
ret void
}