int set_input_volume(int fd_mixer, int cmd_read, int cmd_write, int vol) {
  int ret, err = 0;
  int mem = (vol << 8) | vol;
  vol = mem;
  ret = ioctl(fd_mixer, cmd_write, &mem);
  if ((ret < 0) || (vol != mem)) {
    err++;
    printf("%s: "
           "Failed to set the volume on the selected device\n",
           __FUNCTION__);
  }
  ret = ioctl(fd_mixer, cmd_read, &mem);
  if (ret < 0) {
    err++;
    printf("%s: "
           "Failed to get the volume on the selected device\n",
           __FUNCTION__);
  }
  if ((ret >= 0) && (vol != mem)) {
    err++;
    printf("%s: "
           "Volume set: %04x, get: %04x\n",
           __FUNCTION__, vol, mem);
  }
  return err;
}


x86 assembly (clang, -O0):
<set_input_volume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1177 <set_input_volume+0x57>
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1195 <set_input_volume+0x75>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    0xe79(%rip),%rdi
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d1 <set_input_volume+0xb1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jl     120b <set_input_volume+0xeb>
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     120b <set_input_volume+0xeb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe7e(%rip),%rdi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_input_volume>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
mov    %ecx,%ebp
shl    $0x8,%ebp
or     %ecx,%ebp
mov    %ebp,0x4(%rsp)
xor    %r15d,%r15d
lea    0x4(%rsp),%rax
mov    %edx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %eax,%eax
js     1155 <set_input_volume+0x35>
cmp    0x4(%rsp),%ebp
je     1170 <set_input_volume+0x50>
lea    0xea4(%rip),%rdi
lea    0xed2(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%r15d
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %eax,%eax
js     11aa <set_input_volume+0x8a>
mov    0x4(%rsp),%ecx
cmp    %ecx,%ebp
je     11c3 <set_input_volume+0xa3>
add    $0x1,%r15d
lea    0xee3(%rip),%rdi
lea    0xe96(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c3 <set_input_volume+0xa3>
add    $0x1,%r15d
lea    0xe91(%rip),%rdi
lea    0xe79(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"%s: Failed to set the volume on the selected device\0A\00"
@__FUNCTION__.set_input_volume = [17 x i8] c"set_input_volume\00"
@.str.1 = [53 x i8] c"%s: Failed to get the volume on the selected device\0A\00"
@.str.2 = [33 x i8] c"%s: Volume set: %04x, get: %04x\0A\00"
define i32 @set_input_volume(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
%12 = load i32, i32* %8
%13 = shl i32 %12, 8
%14 = load i32, i32* %8
%15 = or i32 %13, %14
store i32 %15, i32* %11
%16 = load i32, i32* %11
store i32 %16, i32* %8
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %17, i32 %18, i32* %11)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %4
%23 = load i32, i32* %8
%24 = load i32, i32* %11
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22, %4
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
store i32 %28, i32* %10
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_volume, i64 0, i64 0))
br label %30
30: ; preds = %26, %22
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %31, i32 %32, i32* %11)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_volume, i64 0, i64 0))
br label %40
40: ; preds = %36, %30
%41 = load i32, i32* %9
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = load i32, i32* %8
%45 = load i32, i32* %11
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
%50 = load i32, i32* %8
%51 = load i32, i32* %11
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_volume, i64 0, i64 0), i32 %50, i32 %51)
br label %53
53: ; preds = %47, %43, %40
%54 = load i32, i32* %10
ret i32 %54
}

LLVM IR (-O2):
@.str = [53 x i8] c"%s: Failed to set the volume on the selected device\0A\00"
@__FUNCTION__.set_input_volume = [17 x i8] c"set_input_volume\00"
@.str.1 = [53 x i8] c"%s: Failed to get the volume on the selected device\0A\00"
@.str.2 = [33 x i8] c"%s: Volume set: %04x, get: %04x\0A\00"
define i32 @set_input_volume(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = shl i32 %3, 8
%8 = or i32 %7, %3
store i32 %8, i32* %5
%9 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 %2, i32* %5)
%10 = icmp sgt i32 %9, -1
%11 = load i32, i32* %5
%12 = icmp eq i32 %8, %11
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %16, label %14
14: ; preds = %4
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_volume, i64 0, i64 0))
br label %16
16: ; preds = %4, %14
%17 = phi i32 [ 1, %14 ], [ 0, %4 ]
%18 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 %1, i32* %5)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = add nuw nsw i32 %17, 1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_volume, i64 0, i64 0))
br label %29
23: ; preds = %16
%24 = load i32, i32* %5
%25 = icmp eq i32 %8, %24
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = add nuw nsw i32 %17, 1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_volume, i64 0, i64 0), i32 %8, i32 %24)
br label %29
29: ; preds = %20, %26, %23
%30 = phi i32 [ %27, %26 ], [ %17, %23 ], [ %21, %20 ]
ret i32 %30
}