int set_output_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) {
    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_output_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)
jge    1189 <set_output_volume+0x69>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    0xe85(%rip),%rdi
lea    0xeb3(%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    11c5 <set_output_volume+0xa5>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jl     11ff <set_output_volume+0xdf>
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11ff <set_output_volume+0xdf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe8b(%rip),%rdi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_output_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
jns    116a <set_output_volume+0x4a>
lea    0xeaa(%rip),%rdi
lea    0xed8(%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     11a4 <set_output_volume+0x84>
mov    0x4(%rsp),%ecx
cmp    %ecx,%ebp
je     11bd <set_output_volume+0x9d>
add    $0x1,%r15d
lea    0xeea(%rip),%rdi
lea    0xe9c(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11bd <set_output_volume+0x9d>
add    $0x1,%r15d
lea    0xe98(%rip),%rdi
lea    0xe7f(%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_output_volume = [18 x i8] c"set_output_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_output_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 %22, label %26
22: ; preds = %4
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
store i32 %24, i32* %10
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_volume, i64 0, i64 0))
br label %26
26: ; preds = %22, %4
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %27, i32 %28, i32* %11)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
store i32 %34, i32* %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_volume, i64 0, i64 0))
br label %36
36: ; preds = %32, %26
%37 = load i32, i32* %9
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load i32, i32* %8
%41 = load i32, i32* %11
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
%46 = load i32, i32* %8
%47 = load i32, i32* %11
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_volume, i64 0, i64 0), i32 %46, i32 %47)
br label %49
49: ; preds = %43, %39, %36
%50 = load i32, i32* %10
ret i32 %50
}

LLVM IR (-O2):
@.str = [53 x i8] c"%s: Failed to set the volume on the selected device\0A\00"
@__FUNCTION__.set_output_volume = [18 x i8] c"set_output_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_output_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 slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_volume, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
%14 = phi i32 [ 1, %11 ], [ 0, %4 ]
%15 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 %1, i32* %5)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = add nuw nsw i32 %14, 1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_volume, i64 0, i64 0))
br label %26
20: ; preds = %13
%21 = load i32, i32* %5
%22 = icmp eq i32 %8, %21
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = add nuw nsw i32 %14, 1
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_volume, i64 0, i64 0), i32 %8, i32 %21)
br label %26
26: ; preds = %17, %23, %20
%27 = phi i32 [ %24, %23 ], [ %14, %20 ], [ %18, %17 ]
ret i32 %27
}