int set_bits(int fd_audio) {
  int err = 0;
  int ret, val;
  val = 0x00000008;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 5)),
              &val);
  if ((val != 0x00000008) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_BITS (%08x, %08x)\n",
           __FUNCTION__, val, ret);
    err++;
  }
  ret = ioctl(
      fd_audio,
      ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 5)),
      &val);
  if (val != 0x00000010) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_READ_BITS\n",
           __FUNCTION__);
    err++;
  }
  return err;
}


x86 assembly (clang, -O0):
<set_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x8,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045005,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x8,-0x10(%rbp)
jne    1163 <set_bits+0x43>
cmpl   $0x0,-0xc(%rbp)
je     1187 <set_bits+0x67>
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe90(%rip),%rdi
lea    0xec1(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x20045005,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x10,-0x10(%rbp)
je     11c5 <set_bits+0xa5>
lea    0xe93(%rip),%rdi
lea    0xe83(%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_bits>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movl   $0x8,0x4(%rsp)
xor    %ebx,%ebx
lea    0x4(%rsp),%rdx
mov    $0x60045005,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x8,%edx
jne    114d <set_bits+0x2d>
test   %eax,%eax
je     1169 <set_bits+0x49>
lea    0xeac(%rip),%rdi
lea    0xedd(%rip),%rsi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x20045005,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmpl   $0x10,0x4(%rsp)
je     119b <set_bits+0x7b>
lea    0xeb7(%rip),%rdi
lea    0xea7(%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 = [56 x i8] c"%s: Error with IOCTL SOUND_PCM_WRITE_BITS (%08x, %08x)\0A\00"
@__FUNCTION__.set_bits = [9 x i8] c"set_bits\00"
@.str.1 = [42 x i8] c"%s: Error with IOCTL SOUND_PCM_READ_BITS\0A\00"
define i32 @set_bits(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 8, i32* %5
%6 = load i32, i32* %2
%7 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %6, i32 1610895365, i32* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 8
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 %19
13: ; preds = %10, %1
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.set_bits, i64 0, i64 0), i32 %14, i32 %15)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %13, %10
%20 = load i32, i32* %2
%21 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %20, i32 537153541, i32* %5)
store i32 %21, i32* %4
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 16
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.set_bits, i64 0, i64 0))
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %28
28: ; preds = %24, %19
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [56 x i8] c"%s: Error with IOCTL SOUND_PCM_WRITE_BITS (%08x, %08x)\0A\00"
@__FUNCTION__.set_bits = [9 x i8] c"set_bits\00"
@.str.1 = [42 x i8] c"%s: Error with IOCTL SOUND_PCM_READ_BITS\0A\00"
define i32 @set_bits(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 8, i32* %2
%4 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895365, i32* %2)
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 8
%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 ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.set_bits, i64 0, i64 0), i32 %5, i32 %4)
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ 1, %9 ], [ 0, %1 ]
%13 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 537153541, i32* %2)
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 16
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.set_bits, i64 0, i64 0))
%18 = add nuw nsw i32 %12, 1
br label %19
19: ; preds = %16, %11
%20 = phi i32 [ %18, %16 ], [ %12, %11 ]
ret i32 %20
}