int set_channels(int fd_audio) {
  int err = 0;
  int ret, val;
  val = 1;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 6)),
              &val);
  if ((val != 1) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_CHANNELS (%d)\n",
           __FUNCTION__, val);
    err++;
  }
  val = 0;
  ret = ioctl(
      fd_audio,
      ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 6)),
      &val);
  if ((val != 1) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_READ_CHANNELS (%d)\n",
           __FUNCTION__, val);
    err++;
  }
  val = 2;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 6)),
              &val);
  if ((val != 2) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_CHANNELS (%d)\n",
           __FUNCTION__, val);
    err++;
  }
  val = 0;
  ret = ioctl(
      fd_audio,
      ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 6)),
      &val);
  if ((val != 2) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_READ_CHANNELS (%d)\n",
           __FUNCTION__, val);
    err++;
  }
  val = 4;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 6)),
              &val);
  if ((val != 2) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_CHANNELS (%d)\n",
           __FUNCTION__, val);
    err++;
  }
  val = 0;
  ret = ioctl(
      fd_audio,
      ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 6)),
      &val);
  if ((val != 2) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_READ_CHANNELS (%d)\n",
           __FUNCTION__, val);
    err++;
  }
  return err;
}


x86 assembly (clang, -O0):
<set_channels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045006,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    1163 <set_channels+0x43>
cmpl   $0x0,-0xc(%rbp)
je     1184 <set_channels+0x64>
mov    -0x10(%rbp),%edx
lea    0xe93(%rip),%rdi
lea    0xec0(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20045006,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11b5 <set_channels+0x95>
cmpl   $0x0,-0xc(%rbp)
je     11d6 <set_channels+0xb6>
mov    -0x10(%rbp),%edx
lea    0xe82(%rip),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045006,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x10(%rbp)
jne    1207 <set_channels+0xe7>
cmpl   $0x0,-0xc(%rbp)
je     1228 <set_channels+0x108>
mov    -0x10(%rbp),%edx
lea    0xdef(%rip),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20045006,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x10(%rbp)
jne    1259 <set_channels+0x139>
cmpl   $0x0,-0xc(%rbp)
je     127a <set_channels+0x15a>
mov    -0x10(%rbp),%edx
lea    0xdde(%rip),%rdi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045006,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x10(%rbp)
jne    12ab <set_channels+0x18b>
cmpl   $0x0,-0xc(%rbp)
je     12cc <set_channels+0x1ac>
mov    -0x10(%rbp),%edx
lea    0xd4b(%rip),%rdi
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20045006,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x10(%rbp)
jne    12fd <set_channels+0x1dd>
cmpl   $0x0,-0xc(%rbp)
je     131e <set_channels+0x1fe>
mov    -0x10(%rbp),%edx
lea    0xd3a(%rip),%rdi
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_channels>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movl   $0x1,0x4(%rsp)
xor    %ebx,%ebx
lea    0x4(%rsp),%rdx
mov    $0x60045006,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x1,%edx
jne    114d <set_channels+0x2d>
test   %eax,%eax
je     1167 <set_channels+0x47>
lea    0xeac(%rip),%rdi
lea    0xed9(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x20045006,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x1,%edx
jne    118f <set_channels+0x6f>
test   %eax,%eax
je     11a7 <set_channels+0x87>
lea    0xeab(%rip),%rdi
lea    0xe97(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movl   $0x2,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x60045006,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x2,%edx
jne    11cf <set_channels+0xaf>
test   %eax,%eax
je     11e7 <set_channels+0xc7>
lea    0xe2a(%rip),%rdi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x20045006,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x2,%edx
jne    120f <set_channels+0xef>
test   %eax,%eax
je     1227 <set_channels+0x107>
lea    0xe2b(%rip),%rdi
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movl   $0x4,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x60045006,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x2,%edx
jne    124f <set_channels+0x12f>
test   %eax,%eax
je     1267 <set_channels+0x147>
lea    0xdaa(%rip),%rdi
lea    0xdd7(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x20045006,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x2,%edx
jne    128f <set_channels+0x16f>
test   %eax,%eax
je     12a7 <set_channels+0x187>
lea    0xdab(%rip),%rdi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"%s: Error with IOCTL SOUND_PCM_WRITE_CHANNELS (%d)\0A\00"
@__FUNCTION__.set_channels = [13 x i8] c"set_channels\00"
@.str.1 = [51 x i8] c"%s: Error with IOCTL SOUND_PCM_READ_CHANNELS (%d)\0A\00"
define i32 @set_channels(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %5
%6 = load i32, i32* %2
%7 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %6, i32 1610895366, i32* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10, %1
%14 = load i32, i32* %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %18
18: ; preds = %13, %10
store i32 0, i32* %5
%19 = load i32, i32* %2
%20 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %19, i32 537153542, i32* %5)
store i32 %20, i32* %4
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23, %18
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %31
31: ; preds = %26, %23
store i32 2, i32* %5
%32 = load i32, i32* %2
%33 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %32, i32 1610895366, i32* %5)
store i32 %33, i32* %4
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 2
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36, %31
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %44
44: ; preds = %39, %36
store i32 0, i32* %5
%45 = load i32, i32* %2
%46 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %45, i32 537153542, i32* %5)
store i32 %46, i32* %4
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, 2
br i1 %48, label %52, label %49
49: ; preds = %44
%50 = load i32, i32* %4
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %49, %44
%53 = load i32, i32* %5
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 1
store i32 %56, i32* %3
br label %57
57: ; preds = %52, %49
store i32 4, i32* %5
%58 = load i32, i32* %2
%59 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %58, i32 1610895366, i32* %5)
store i32 %59, i32* %4
%60 = load i32, i32* %5
%61 = icmp ne i32 %60, 2
br i1 %61, label %65, label %62
62: ; preds = %57
%63 = load i32, i32* %4
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %62, %57
%66 = load i32, i32* %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
br label %70
70: ; preds = %65, %62
store i32 0, i32* %5
%71 = load i32, i32* %2
%72 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %71, i32 537153542, i32* %5)
store i32 %72, i32* %4
%73 = load i32, i32* %5
%74 = icmp ne i32 %73, 2
br i1 %74, label %78, label %75
75: ; preds = %70
%76 = load i32, i32* %4
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %75, %70
%79 = load i32, i32* %5
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %79)
%81 = load i32, i32* %3
%82 = add nsw i32 %81, 1
store i32 %82, i32* %3
br label %83
83: ; preds = %78, %75
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [52 x i8] c"%s: Error with IOCTL SOUND_PCM_WRITE_CHANNELS (%d)\0A\00"
@__FUNCTION__.set_channels = [13 x i8] c"set_channels\00"
@.str.1 = [51 x i8] c"%s: Error with IOCTL SOUND_PCM_READ_CHANNELS (%d)\0A\00"
define i32 @set_channels(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895366, i32* %2)
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 1
%7 = icmp ne i32 %4, 0
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %5)
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ 1, %9 ], [ 0, %1 ]
store i32 0, i32* %2
%13 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 537153542, i32* %2)
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 1
%16 = icmp ne i32 %13, 0
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %14)
%20 = add nuw nsw i32 %12, 1
br label %21
21: ; preds = %11, %18
%22 = phi i32 [ %20, %18 ], [ %12, %11 ]
store i32 2, i32* %2
%23 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895366, i32* %2)
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 2
%26 = icmp ne i32 %23, 0
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %24)
%30 = add nuw nsw i32 %22, 1
br label %31
31: ; preds = %21, %28
%32 = phi i32 [ %30, %28 ], [ %22, %21 ]
store i32 0, i32* %2
%33 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 537153542, i32* %2)
%34 = load i32, i32* %2
%35 = icmp ne i32 %34, 2
%36 = icmp ne i32 %33, 0
%37 = select i1 %35, i1 true, i1 %36
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %34)
%40 = add nuw nsw i32 %32, 1
br label %41
41: ; preds = %31, %38
%42 = phi i32 [ %40, %38 ], [ %32, %31 ]
store i32 4, i32* %2
%43 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895366, i32* %2)
%44 = load i32, i32* %2
%45 = icmp ne i32 %44, 2
%46 = icmp ne i32 %43, 0
%47 = select i1 %45, i1 true, i1 %46
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %44)
%50 = add nuw nsw i32 %42, 1
br label %51
51: ; preds = %41, %48
%52 = phi i32 [ %50, %48 ], [ %42, %41 ]
store i32 0, i32* %2
%53 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 537153542, i32* %2)
%54 = load i32, i32* %2
%55 = icmp ne i32 %54, 2
%56 = icmp ne i32 %53, 0
%57 = select i1 %55, i1 true, i1 %56
br i1 %57, label %58, label %61
58: ; preds = %51
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__FUNCTION__.set_channels, i64 0, i64 0), i32 %54)
%60 = add nuw nsw i32 %52, 1
br label %61
61: ; preds = %51, %58
%62 = phi i32 [ %60, %58 ], [ %52, %51 ]
ret i32 %62
}