#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_WRITE(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 *);
void volSet(int percent) {
  int ret, vol;
  int mixerfd = open("/dev/mixer", O_RDONLY);
  if (mixerfd < 0) {
    perror("/dev/mixer: ");
    return;
  }
  if (percent > 100)
    percent = 100;
  else if (percent < 0)
    percent = 0;
  vol = (percent << 8) + percent;
  ret = ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_PCM), &vol);
  if (ret < 0)
    perror("Setting PCM volume: ");
  close(mixerfd);
}


x86 assembly (clang, -O0):
<volSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    118e <volSet+0x3e>
lea    0xe87(%rip),%rdi
call   1070 <perror@plt>
jmp    1209 <volSet+0xb9>
cmpl   $0x64,-0x4(%rbp)
jle    11a4 <volSet+0x54>
movl   $0x64,-0x4(%rbp)
jmp    11ba <volSet+0x6a>
cmpl   $0x0,-0x4(%rbp)
jge    11b5 <volSet+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11ba <volSet+0x6a>
mov    -0x4(%rbp),%eax
shl    $0x8,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1050 <MIXER_WRITE@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1201 <volSet+0xb1>
lea    0xe1c(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<volSet>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11bb <volSet+0x6b>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebp,%ebp
cmovns %ebp,%eax
mov    %eax,%ecx
shl    $0x8,%ecx
add    %eax,%ecx
cmp    $0x65,%ebp
mov    $0x6464,%eax
cmovl  %ecx,%eax
mov    %eax,0x4(%rsp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <MIXER_WRITE@plt>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <ioctl@plt>
test   %eax,%eax
js     11cd <volSet+0x7d>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe49(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <perror@plt>
lea    0xe44(%rip),%rdi
call   1070 <perror@plt>
jmp    11ad <volSet+0x5d>

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"Setting PCM volume: \00"
define void @volSet(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %37
12: ; preds = %1
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 100
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 100, i32* %2
br label %21
16: ; preds = %12
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 0, i32* %2
br label %20
20: ; preds = %19, %16
br label %21
21: ; preds = %20, %15
%22 = load i32, i32* %2
%23 = shl i32 %22, 8
%24 = load i32, i32* %2
%25 = add nsw i32 %23, %24
store i32 %25, i32* %4
%26 = load i32, i32* %5
%27 = load i32, i32* @SOUND_MIXER_PCM
%28 = call i32 @MIXER_WRITE(i32 %27)
%29 = call i32 @ioctl(i32 %26, i32 %28, i32* %4)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = load i32, i32* %5
%36 = call i32 @close(i32 %35)
br label %37
37: ; preds = %34, %10
ret void
}

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"Setting PCM volume: \00"
define void @volSet(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %23
9: ; preds = %1
%10 = icmp sgt i32 %0, 100
%11 = icmp sgt i32 %0, 0
%12 = select i1 %11, i32 %0, i32 0
%13 = mul i32 %12, 257
%14 = select i1 %10, i32 25700, i32 %13
store i32 %14, i32* %2
%15 = load i32, i32* @SOUND_MIXER_PCM
%16 = tail call i32 @MIXER_WRITE(i32 %15)
%17 = call i32 @ioctl(i32 %5, i32 %16, i32* %2)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %9
%22 = call i32 @close(i32 %5)
br label %23
23: ; preds = %21, %7
ret void
}