int set_speed(int fd_audio) {
  int err = 0;
  int ret, val;
  val = 8000;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 2)),
              &val);
  if ((val != 8000) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_RATE %d %d\n",
           __FUNCTION__, val, ret);
    err++;
  }
  val = 32000;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 2)),
              &val);
  if ((val != 32000) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_RATE %d %d\n",
           __FUNCTION__, val, ret);
    err++;
  }
  val = 44100;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 2)),
              &val);
  if ((val != 44100) || (ret != 0)) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_RATE %d %d\n",
           __FUNCTION__, val, ret);
    err++;
  }
  val = 4000;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 2)),
              &val);
  if (val != 8000) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_RATE %d %d\n",
           __FUNCTION__, val, ret);
    err++;
  }
  val = 128000;
  ret = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 2)),
              &val);
  if (val != 96000) {
    printf("%s: "
           "Error with IOCTL SOUND_PCM_WRITE_RATE %d %d\n",
           __FUNCTION__, val, ret);
    err++;
  }
  return err;
}


x86 assembly (clang, -O0):
<set_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1f40,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045002,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1f40,-0x10(%rbp)
jne    1166 <set_speed+0x46>
cmpl   $0x0,-0xc(%rbp)
je     118a <set_speed+0x6a>
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe8d(%rip),%rdi
lea    0xeb7(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x7d00,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045002,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x7d00,-0x10(%rbp)
jne    11be <set_speed+0x9e>
cmpl   $0x0,-0xc(%rbp)
je     11e2 <set_speed+0xc2>
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe35(%rip),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0xac44,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045002,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xac44,-0x10(%rbp)
jne    1216 <set_speed+0xf6>
cmpl   $0x0,-0xc(%rbp)
je     123a <set_speed+0x11a>
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xddd(%rip),%rdi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0xfa0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045002,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1f40,-0x10(%rbp)
je     1288 <set_speed+0x168>
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xd8f(%rip),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x1f400,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x60045002,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x17700,-0x10(%rbp)
je     12d6 <set_speed+0x1b6>
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xd41(%rip),%rdi
lea    0xd6b(%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_speed>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movl   $0x1f40,0x4(%rsp)
xor    %ebx,%ebx
lea    0x4(%rsp),%rdx
mov    $0x60045002,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x1f40,%edx
jne    1150 <set_speed+0x30>
test   %eax,%eax
je     116c <set_speed+0x4c>
lea    0xea9(%rip),%rdi
lea    0xed3(%rip),%rsi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
movl   $0x7d00,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x60045002,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x7d00,%edx
jne    1197 <set_speed+0x77>
test   %eax,%eax
je     11b1 <set_speed+0x91>
lea    0xe62(%rip),%rdi
lea    0xe8c(%rip),%rsi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movl   $0xac44,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x60045002,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0xac44,%edx
jne    11dc <set_speed+0xbc>
test   %eax,%eax
je     11f6 <set_speed+0xd6>
lea    0xe1d(%rip),%rdi
lea    0xe47(%rip),%rsi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movl   $0xfa0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x60045002,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x1f40,%edx
je     1237 <set_speed+0x117>
lea    0xddc(%rip),%rdi
lea    0xe06(%rip),%rsi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movl   $0x1f400,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x60045002,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
mov    0x4(%rsp),%edx
cmp    $0x17700,%edx
je     1278 <set_speed+0x158>
lea    0xd9b(%rip),%rdi
lea    0xdc5(%rip),%rsi
mov    %eax,%ecx
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 = [49 x i8] c"%s: Error with IOCTL SOUND_PCM_WRITE_RATE %d %d\0A\00"
@__FUNCTION__.set_speed = [10 x i8] c"set_speed\00"
define i32 @set_speed(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 8000, i32* %5
%6 = load i32, i32* %2
%7 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %6, i32 1610895362, i32* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 8000
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 ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, 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
store i32 32000, i32* %5
%20 = load i32, i32* %2
%21 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %20, i32 1610895362, i32* %5)
store i32 %21, i32* %4
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 32000
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24, %19
%28 = load i32, i32* %5
%29 = load i32, i32* %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %28, i32 %29)
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %27, %24
store i32 44100, i32* %5
%34 = load i32, i32* %2
%35 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %34, i32 1610895362, i32* %5)
store i32 %35, i32* %4
%36 = load i32, i32* %5
%37 = icmp ne i32 %36, 44100
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = load i32, i32* %4
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38, %33
%42 = load i32, i32* %5
%43 = load i32, i32* %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %42, i32 %43)
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %47
47: ; preds = %41, %38
store i32 4000, i32* %5
%48 = load i32, i32* %2
%49 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %48, i32 1610895362, i32* %5)
store i32 %49, i32* %4
%50 = load i32, i32* %5
%51 = icmp ne i32 %50, 8000
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = load i32, i32* %5
%54 = load i32, i32* %4
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %53, i32 %54)
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %58
58: ; preds = %52, %47
store i32 128000, i32* %5
%59 = load i32, i32* %2
%60 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %59, i32 1610895362, i32* %5)
store i32 %60, i32* %4
%61 = load i32, i32* %5
%62 = icmp ne i32 %61, 96000
br i1 %62, label %63, label %69
63: ; preds = %58
%64 = load i32, i32* %5
%65 = load i32, i32* %4
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %64, i32 %65)
%67 = load i32, i32* %3
%68 = add nsw i32 %67, 1
store i32 %68, i32* %3
br label %69
69: ; preds = %63, %58
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [49 x i8] c"%s: Error with IOCTL SOUND_PCM_WRITE_RATE %d %d\0A\00"
@__FUNCTION__.set_speed = [10 x i8] c"set_speed\00"
define i32 @set_speed(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 8000, i32* %2
%4 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895362, i32* %2)
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 8000
%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 ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %5, i32 %4)
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ 1, %9 ], [ 0, %1 ]
store i32 32000, i32* %2
%13 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895362, i32* %2)
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 32000
%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 ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %14, i32 %13)
%20 = add nuw nsw i32 %12, 1
br label %21
21: ; preds = %11, %18
%22 = phi i32 [ %20, %18 ], [ %12, %11 ]
store i32 44100, i32* %2
%23 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895362, i32* %2)
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 44100
%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 ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %24, i32 %23)
%30 = add nuw nsw i32 %22, 1
br label %31
31: ; preds = %21, %28
%32 = phi i32 [ %30, %28 ], [ %22, %21 ]
store i32 4000, i32* %2
%33 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895362, i32* %2)
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, 8000
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %34, i32 %33)
%38 = add nuw nsw i32 %32, 1
br label %39
39: ; preds = %36, %31
%40 = phi i32 [ %38, %36 ], [ %32, %31 ]
store i32 128000, i32* %2
%41 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @ioctl to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 1610895362, i32* %2)
%42 = load i32, i32* %2
%43 = icmp eq i32 %42, 96000
br i1 %43, label %47, label %44
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__FUNCTION__.set_speed, i64 0, i64 0), i32 %42, i32 %41)
%46 = add nuw nsw i32 %40, 1
br label %47
47: ; preds = %44, %39
%48 = phi i32 [ %46, %44 ], [ %40, %39 ]
ret i32 %48
}