#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*/ MIXER_READ(int /*<<< orphan*/);
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOUND_MIXER_PCM;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int volGet(void) {
  int vol, ret;
  int mixerfd = open("/dev/mixer", O_RDONLY);
  if (mixerfd < 0) {
    perror("/dev/mixer: ");
    return 0;
  }
  ret = ioctl(mixerfd, MIXER_READ(SOUND_MIXER_PCM), &vol);
  if (ret < 0)
    perror("Reading PCM volume: ");
  close(mixerfd);
  return vol & 0xff;
}


x86 assembly (clang, -O0):
<volGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1192 <volGet+0x42>
lea    0xe8a(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <volGet+0x90>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1050 <MIXER_READ@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11cd <volGet+0x7d>
lea    0xe50(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<volGet>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a2 <volGet+0x52>
mov    %eax,%ebx
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1050 <MIXER_READ@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <ioctl@plt>
test   %eax,%eax
js     11b2 <volGet+0x62>
mov    %ebx,%edi
call   1040 <close@plt>
movzbl 0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
jmp    119c <volGet+0x4c>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
jmp    1190 <volGet+0x40>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/mixer\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"/dev/mixer: \00"
@SOUND_MIXER_PCM = global i32 0
@.str.2 = [21 x i8] c"Reading PCM volume: \00"
define i32 @volGet() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %25
11: ; preds = %0
%12 = load i32, i32* %4
%13 = load i32, i32* @SOUND_MIXER_PCM
%14 = call i32 @MIXER_READ(i32 %13)
%15 = call i32 @ioctl(i32 %12, i32 %14, i32* %2)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = load i32, i32* %4
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %2
%24 = and i32 %23, 255
store i32 %24, i32* %1
br label %25
25: ; preds = %20, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/mixer\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"/dev/mixer: \00"
@SOUND_MIXER_PCM = global i32 0
@.str.2 = [21 x i8] c"Reading PCM volume: \00"
define i32 @volGet() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %19
8: ; preds = %0
%9 = load i32, i32* @SOUND_MIXER_PCM
%10 = tail call i32 @MIXER_READ(i32 %9)
%11 = call i32 @ioctl(i32 %4, i32 %10, i32* %1)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = call i32 @close(i32 %4)
%17 = load i32, i32* %1
%18 = and i32 %17, 255
br label %19
19: ; preds = %15, %6
%20 = phi i32 [ 0, %6 ], [ %18, %15 ]
ret i32 %20
}