int set_input_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) | 0xff)),
              &val);
  if ((val != device) || (ret != 0)) {
    err++;
    printf("%s: "
           "Failed to set the input device %x\n",
           __FUNCTION__, device);
  }
  ret = ioctl(
      fd_mixer,
      ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xff)),
      &val);
  if ((val != device) || (ret != 0)) {
    err++;
    printf("%s: "
           "Failed to get the input device %x\n",
           __FUNCTION__, device);
  }
  switch (device) {
  case (1 << 20):
    err += set_input_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 20)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 20)),
        50);
    err += set_input_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 20)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 20)),
        75);
    break;
  case (1 << 6):
    err += set_input_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 6)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 6)),
        50);
    err += set_input_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 6)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 6)),
        75);
    break;
  case (1 << 7):
    err += set_input_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 7)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 7)),
        50);
    err += set_input_volume(
        fd_mixer,
        ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 7)),
        ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
               ('M' << 8) | 7)),
        75);
    break;
  default:
    err++;
    break;
  }
  return err;
}


x86 assembly (clang, -O0):
<set_input_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    $0x60044dff,%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_input_device+0x47>
cmpl   $0x0,-0x10(%rbp)
je     1198 <set_input_device+0x68>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edx
lea    0xe76(%rip),%rdi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x20044dff,%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    11c4 <set_input_device+0x94>
cmpl   $0x0,-0x10(%rbp)
je     11e5 <set_input_device+0xb5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edx
lea    0xe61(%rip),%rdi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x40,%eax
je     1262 <set_input_device+0x132>
jmp    11f9 <set_input_device+0xc9>
mov    -0x18(%rbp),%eax
sub    $0x80,%eax
je     12a5 <set_input_device+0x175>
jmp    120c <set_input_device+0xdc>
mov    -0x18(%rbp),%eax
sub    $0x100000,%eax
jne    12e8 <set_input_device+0x1b8>
jmp    121f <set_input_device+0xef>
mov    -0x4(%rbp),%edi
mov    $0x20044d14,%esi
mov    $0x60044d14,%edx
mov    $0x32,%ecx
mov    $0x0,%al
call   1050 <set_input_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20044d14,%esi
mov    $0x60044d14,%edx
mov    $0x4b,%ecx
mov    $0x0,%al
call   1050 <set_input_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12f1 <set_input_device+0x1c1>
mov    -0x4(%rbp),%edi
mov    $0x20044d06,%esi
mov    $0x60044d06,%edx
mov    $0x32,%ecx
mov    $0x0,%al
call   1050 <set_input_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20044d06,%esi
mov    $0x60044d06,%edx
mov    $0x4b,%ecx
mov    $0x0,%al
call   1050 <set_input_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12f1 <set_input_device+0x1c1>
mov    -0x4(%rbp),%edi
mov    $0x20044d07,%esi
mov    $0x60044d07,%edx
mov    $0x32,%ecx
mov    $0x0,%al
call   1050 <set_input_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20044d07,%esi
mov    $0x60044d07,%edx
mov    $0x4b,%ecx
mov    $0x0,%al
call   1050 <set_input_volume@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12f1 <set_input_device+0x1c1>
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_input_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    $0x60044dff,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    %ebx,0xc(%rsp)
jne    115e <set_input_device+0x2e>
test   %eax,%eax
je     117a <set_input_device+0x4a>
lea    0xe9b(%rip),%rdi
lea    0xebb(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebp
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    $0x20044dff,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    %ebx,0xc(%rsp)
jne    1198 <set_input_device+0x68>
test   %eax,%eax
je     11b2 <set_input_device+0x82>
add    $0x1,%ebp
lea    0xe96(%rip),%rdi
lea    0xe7e(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x40,%ebx
je     11f7 <set_input_device+0xc7>
cmp    $0x80,%ebx
je     1223 <set_input_device+0xf3>
cmp    $0x100000,%ebx
jne    125f <set_input_device+0x12f>
mov    %r14d,%edi
mov    $0x20044d14,%esi
mov    $0x60044d14,%edx
mov    $0x32,%ecx
xor    %eax,%eax
call   1050 <set_input_volume@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
mov    $0x20044d14,%esi
mov    $0x60044d14,%edx
jmp    124d <set_input_device+0x11d>
mov    %r14d,%edi
mov    $0x20044d06,%esi
mov    $0x60044d06,%edx
mov    $0x32,%ecx
xor    %eax,%eax
call   1050 <set_input_volume@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
mov    $0x20044d06,%esi
mov    $0x60044d06,%edx
jmp    124d <set_input_device+0x11d>
mov    %r14d,%edi
mov    $0x20044d07,%esi
mov    $0x60044d07,%edx
mov    $0x32,%ecx
xor    %eax,%eax
call   1050 <set_input_volume@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
mov    $0x20044d07,%esi
mov    $0x60044d07,%edx
mov    $0x4b,%ecx
xor    %eax,%eax
call   1050 <set_input_volume@plt>
mov    %eax,%ebp
add    %ebx,%ebp
jmp    1262 <set_input_device+0x132>
add    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"%s: Failed to set the input device %x\0A\00"
@__FUNCTION__.set_input_device = [17 x i8] c"set_input_device\00"
@.str.1 = [39 x i8] c"%s: Failed to get the input device %x\0A\00"
define i32 @set_input_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 1610894847, 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 %22
17: ; preds = %14, %2
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_device, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %17, %14
%23 = load i32, i32* %3
%24 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %23, i32 537153023, i32* %5)
store i32 %24, i32* %6
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = icmp ne i32 %25, %26
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28, %22
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_device, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %31, %28
%37 = load i32, i32* %4
switch i32 %37, label %65 [
i32 1048576, label %38
i32 64, label %47
i32 128, label %56
]
38: ; preds = %36
%39 = load i32, i32* %3
%40 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %39, i32 537152788, i32 1610894612, i32 50)
%41 = load i32, i32* %7
%42 = add nsw i32 %41, %40
store i32 %42, i32* %7
%43 = load i32, i32* %3
%44 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %43, i32 537152788, i32 1610894612, i32 75)
%45 = load i32, i32* %7
%46 = add nsw i32 %45, %44
store i32 %46, i32* %7
br label %68
47: ; preds = %36
%48 = load i32, i32* %3
%49 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %48, i32 537152774, i32 1610894598, i32 50)
%50 = load i32, i32* %7
%51 = add nsw i32 %50, %49
store i32 %51, i32* %7
%52 = load i32, i32* %3
%53 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %52, i32 537152774, i32 1610894598, i32 75)
%54 = load i32, i32* %7
%55 = add nsw i32 %54, %53
store i32 %55, i32* %7
br label %68
56: ; preds = %36
%57 = load i32, i32* %3
%58 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %57, i32 537152775, i32 1610894599, i32 50)
%59 = load i32, i32* %7
%60 = add nsw i32 %59, %58
store i32 %60, i32* %7
%61 = load i32, i32* %3
%62 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %61, i32 537152775, i32 1610894599, i32 75)
%63 = load i32, i32* %7
%64 = add nsw i32 %63, %62
store i32 %64, i32* %7
br label %68
65: ; preds = %36
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %68
68: ; preds = %65, %56, %47, %38
%69 = load i32, i32* %7
ret i32 %69
}

LLVM IR (-O2):
@.str = [39 x i8] c"%s: Failed to set the input device %x\0A\00"
@__FUNCTION__.set_input_device = [17 x i8] c"set_input_device\00"
@.str.1 = [39 x i8] c"%s: Failed to get the input device %x\0A\00"
define i32 @set_input_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 1610894847, 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 ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_device, i64 0, i64 0), i32 %1)
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 537153023, 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 ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.set_input_device, i64 0, i64 0), i32 %1)
br label %22
22: ; preds = %12, %19
%23 = phi i32 [ %20, %19 ], [ %13, %12 ]
switch i32 %1, label %39 [
i32 1048576, label %24
i32 64, label %29
i32 128, label %34
]
24: ; preds = %22
%25 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152788, i32 1610894612, i32 50)
%26 = add nsw i32 %25, %23
%27 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152788, i32 1610894612, i32 75)
%28 = add nsw i32 %26, %27
br label %41
29: ; preds = %22
%30 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152774, i32 1610894598, i32 50)
%31 = add nsw i32 %30, %23
%32 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152774, i32 1610894598, i32 75)
%33 = add nsw i32 %31, %32
br label %41
34: ; preds = %22
%35 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152775, i32 1610894599, i32 50)
%36 = add nsw i32 %35, %23
%37 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @set_input_volume to i32 (i32, i32, i32, i32, ...)*)(i32 %0, i32 537152775, i32 1610894599, i32 75)
%38 = add nsw i32 %36, %37
br label %41
39: ; preds = %22
%40 = add nuw nsw i32 %23, 1
br label %41
41: ; preds = %39, %34, %29, %24
%42 = phi i32 [ %40, %39 ], [ %38, %34 ], [ %33, %29 ], [ %28, %24 ]
ret i32 %42
}