int set_output_device(int fd_mixer, int device) {
  int val = device;
  int ret;
  int err = 0;
  ret = ioctl(fd_mixer,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xfa)),
              &val);
  if ((val != device) || (ret != 0)) {
    err++;
    printf("%s: "
           "Failed to set the output device\n",
           __FUNCTION__);
  }
  ret = ioctl(
      fd_mixer,
      ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xfa)),
      &val);
  if ((val != device) || (ret != 0)) {
    err++;
    printf("%s: "
           "Failed to get the output device\n",
           __FUNCTION__);
  }
  switch (device) {
  case (1 << 5):
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 5)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 5)),
        50);
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 5)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 5)),
        75);
    break;
  case (1 << 0):
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 0)),
        50);
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 0)),
        75);
    break;
  case (1 << 4):
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 4)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 4)),
        50);
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 4)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 4)),
        75);
    break;
  case (1 << 21):
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 21)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 21)),
        50);
    err += set_output_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 21)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 21)),
        75);
    break;
  default:
    err++;
    break;
  }
  return err;
}


x86 assembly (clang, -O0):
<set_output_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1177 <set_output_device+0x47>
cmpl   $0x0,-0x10(%rbp)
je     1195 <set_output_device+0x65>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    0xe79(%rip),%rdi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x20044dfa,%esi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11c1 <set_output_device+0x91>
cmpl   $0x0,-0x10(%rbp)
je     11df <set_output_device+0xaf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    0xe66(%rip),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     126b <set_output_device+0x13b>
jmp    11f3 <set_output_device+0xc3>
mov    -0x18(%rbp),%eax
sub    $0x10,%eax
je     12ae <set_output_device+0x17e>
jmp    1204 <set_output_device+0xd4>
mov    -0x18(%rbp),%eax
sub    $0x20,%eax
je     1228 <set_output_device+0xf8>
jmp    1215 <set_output_device+0xe5>
mov    -0x18(%rbp),%eax
sub    $0x200000,%eax
je     12f1 <set_output_device+0x1c1>
jmp    1334 <set_output_device+0x204>
mov    -0x4(%rbp),%edi
mov    $0x20044d05,%esi
mov    $0x60044d05,%edx
mov    $0x32,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20044d05,%esi
mov    $0x60044d05,%edx
mov    $0x4b,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    133d <set_output_device+0x20d>
mov    -0x4(%rbp),%edi
mov    $0x20044d00,%esi
mov    $0x60044d00,%edx
mov    $0x32,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20044d00,%esi
mov    $0x60044d00,%edx
mov    $0x4b,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    133d <set_output_device+0x20d>
mov    -0x4(%rbp),%edi
mov    $0x20044d04,%esi
mov    $0x60044d04,%edx
mov    $0x32,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20044d04,%esi
mov    $0x60044d04,%edx
mov    $0x4b,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    133d <set_output_device+0x20d>
mov    -0x4(%rbp),%edi
mov    $0x20044d15,%esi
mov    $0x60044d15,%edx
mov    $0x32,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20044d15,%esi
mov    $0x60044d15,%edx
mov    $0x4b,%ecx
mov    $0x0,%al
call   1050 <set_output_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    133d <set_output_device+0x20d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_output_device>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %esi,0xc(%rsp)
xor    %ebp,%ebp
lea    0xc(%rsp),%rdx
mov    $0x60044dfa,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    %ebx,0xc(%rsp)
jne    115e <set_output_device+0x2e>
test   %eax,%eax
je     1178 <set_output_device+0x48>
lea    0xe9b(%rip),%rdi
lea    0xeb9(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebp
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    $0x20044dfa,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    %ebx,0xc(%rsp)
jne    11dc <set_output_device+0xac>
test   %eax,%eax
jne    11dc <set_output_device+0xac>
cmp    $0x1f,%ebx
jg     11f9 <set_output_device+0xc9>
cmp    $0x1,%ebx
je     1237 <set_output_device+0x107>
cmp    $0x10,%ebx
jne    1232 <set_output_device+0x102>
mov    %r14d,%edi
mov    $0x20044d04,%esi
mov    $0x60044d04,%edx
mov    $0x32,%ecx
xor    %eax,%eax
call   1050 <set_output_volume@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
mov    $0x20044d04,%esi
mov    $0x60044d04,%edx
jmp    128d <set_output_device+0x15d>
add    $0x1,%ebp
lea    0xe51(%rip),%rdi
lea    0xe38(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x1f,%ebx
jle    119b <set_output_device+0x6b>
cmp    $0x200000,%ebx
je     1263 <set_output_device+0x133>
cmp    $0x20,%ebx
jne    1232 <set_output_device+0x102>
mov    %r14d,%edi
mov    $0x20044d05,%esi
mov    $0x60044d05,%edx
mov    $0x32,%ecx
xor    %eax,%eax
call   1050 <set_output_volume@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
mov    $0x20044d05,%esi
mov    $0x60044d05,%edx
jmp    128d <set_output_device+0x15d>
add    $0x1,%ebp
jmp    129d <set_output_device+0x16d>
mov    %r14d,%edi
mov    $0x20044d00,%esi
mov    $0x60044d00,%edx
mov    $0x32,%ecx
xor    %eax,%eax
call   1050 <set_output_volume@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
mov    $0x20044d00,%esi
mov    $0x60044d00,%edx
jmp    128d <set_output_device+0x15d>
mov    %r14d,%edi
mov    $0x20044d15,%esi
mov    $0x60044d15,%edx
mov    $0x32,%ecx
xor    %eax,%eax
call   1050 <set_output_volume@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
mov    $0x20044d15,%esi
mov    $0x60044d15,%edx
mov    $0x4b,%ecx
xor    %eax,%eax
call   1050 <set_output_volume@plt>
mov    %eax,%ebp
add    %ebx,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"%s: Failed to set the output device\0A\00"
@__FUNCTION__.set_output_device = [18 x i8] c"set_output_device\00"
@.str.1 = [37 x i8] c"%s: Failed to get the output device\0A\00"
define i32 @set_output_device(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
store i32 %8, i32* %5
store i32 0, i32* %7
%9 = load i32, i32* %3
%10 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %9, i32 1610894842, i32* %5)
store i32 %10, i32* %6
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %11, %12
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14, %2
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_device, i64 0, i64 0))
br label %21
21: ; preds = %17, %14
%22 = load i32, i32* %3
%23 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %22, i32 537153018, i32* %5)
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = icmp ne i32 %24, %25
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27, %21
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_device, i64 0, i64 0))
br label %34
34: ; preds = %30, %27
%35 = load i32, i32* %4
switch i32 %35, label %72 [
i32 32, label %36
i32 1, label %45
i32 16, label %54
i32 2097152, label %63
]
36: ; preds = %34
%37 = load i32, i32* %3
%38 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %37, i32 537152773, i32 1610894597, i32 50)
%39 = load i32, i32* %7
%40 = add nsw i32 %39, %38
store i32 %40, i32* %7
%41 = load i32, i32* %3
%42 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %41, i32 537152773, i32 1610894597, i32 75)
%43 = load i32, i32* %7
%44 = add nsw i32 %43, %42
store i32 %44, i32* %7
br label %75
45: ; preds = %34
%46 = load i32, i32* %3
%47 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %46, i32 537152768, i32 1610894592, i32 50)
%48 = load i32, i32* %7
%49 = add nsw i32 %48, %47
store i32 %49, i32* %7
%50 = load i32, i32* %3
%51 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %50, i32 537152768, i32 1610894592, i32 75)
%52 = load i32, i32* %7
%53 = add nsw i32 %52, %51
store i32 %53, i32* %7
br label %75
54: ; preds = %34
%55 = load i32, i32* %3
%56 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %55, i32 537152772, i32 1610894596, i32 50)
%57 = load i32, i32* %7
%58 = add nsw i32 %57, %56
store i32 %58, i32* %7
%59 = load i32, i32* %3
%60 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %59, i32 537152772, i32 1610894596, i32 75)
%61 = load i32, i32* %7
%62 = add nsw i32 %61, %60
store i32 %62, i32* %7
br label %75
63: ; preds = %34
%64 = load i32, i32* %3
%65 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %64, i32 537152789, i32 1610894613, i32 50)
%66 = load i32, i32* %7
%67 = add nsw i32 %66, %65
store i32 %67, i32* %7
%68 = load i32, i32* %3
%69 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %68, i32 537152789, i32 1610894613, i32 75)
%70 = load i32, i32* %7
%71 = add nsw i32 %70, %69
store i32 %71, i32* %7
br label %75
72: ; preds = %34
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
br label %75
75: ; preds = %72, %63, %54, %45, %36
%76 = load i32, i32* %7
ret i32 %76
}

LLVM IR (-O2):
@.str = [37 x i8] c"%s: Failed to set the output device\0A\00"
@__FUNCTION__.set_output_device = [18 x i8] c"set_output_device\00"
@.str.1 = [37 x i8] c"%s: Failed to get the output device\0A\00"
define i32 @set_output_device(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 %1, i32* %3
%5 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610894842, i32* %3)
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, %1
%8 = icmp ne i32 %5, 0
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_device, i64 0, i64 0))
br label %12
12: ; preds = %2, %10
%13 = phi i32 [ 1, %10 ], [ 0, %2 ]
%14 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 537153018, i32* %3)
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, %1
%17 = icmp ne i32 %14, 0
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = add nuw nsw i32 %13, 1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.set_output_device, i64 0, i64 0))
br label %22
22: ; preds = %12, %19
%23 = phi i32 [ %20, %19 ], [ %13, %12 ]
switch i32 %1, label %44 [
i32 32, label %24
i32 1, label %29
i32 16, label %34
i32 2097152, label %39
]
24: ; preds = %22
%25 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152773, i32 1610894597, i32 50)
%26 = add nsw i32 %25, %23
%27 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152773, i32 1610894597, i32 75)
%28 = add nsw i32 %26, %27
br label %46
29: ; preds = %22
%30 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152768, i32 1610894592, i32 50)
%31 = add nsw i32 %30, %23
%32 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152768, i32 1610894592, i32 75)
%33 = add nsw i32 %31, %32
br label %46
34: ; preds = %22
%35 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152772, i32 1610894596, i32 50)
%36 = add nsw i32 %35, %23
%37 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152772, i32 1610894596, i32 75)
%38 = add nsw i32 %36, %37
br label %46
39: ; preds = %22
%40 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152789, i32 1610894613, i32 50)
%41 = add nsw i32 %40, %23
%42 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_output_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152789, i32 1610894613, i32 75)
%43 = add nsw i32 %41, %42
br label %46
44: ; preds = %22
%45 = add nuw nsw i32 %23, 1
br label %46
46: ; preds = %44, %39, %34, %29, %24
%47 = phi i32 [ %45, %44 ], [ %43, %39 ], [ %38, %34 ], [ %33, %29 ], [ %28, %24 ]
ret i32 %47
}