#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SNDCTL_DSP_CHANNELS;
int /*<<< orphan*/ SNDCTL_DSP_SETFMT;
int /*<<< orphan*/ SOUND_PCM_WRITE_RATE;
scalar_t__ get_audio_bits(int /*<<< orphan*/ *);
int get_audio_channels(int /*<<< orphan*/ *);
int get_audio_frq(int /*<<< orphan*/ *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, int, int, int);
int set_audio_config(int fd_audio, FILE *file) {
  int tmp, format, frequency, channels;
  tmp = format = (int)get_audio_bits(file);
  ioctl(fd_audio, SNDCTL_DSP_SETFMT, &format);
  if (tmp != format)
    return -1;
  tmp = frequency = get_audio_frq(file);
  ioctl(fd_audio, SOUND_PCM_WRITE_RATE, &frequency);
  if (tmp != frequency)
    return -1;
  tmp = channels = get_audio_channels(file);
  ioctl(fd_audio, SNDCTL_DSP_CHANNELS, &channels);
  if (tmp != channels)
    return -1;
  printf("Configuration : %d %d %d\n", format, frequency, channels);
  return 0;
}


x86 assembly (clang, -O0):
<set_audio_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <get_audio_bits@plt>
mov    %eax,-0x18(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     119b <set_audio_config+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <set_audio_config+0xdf>
mov    -0x10(%rbp),%rdi
call   1050 <get_audio_frq@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11d7 <set_audio_config+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <set_audio_config+0xdf>
mov    -0x10(%rbp),%rdi
call   1070 <get_audio_channels@plt>
mov    %eax,-0x20(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1213 <set_audio_config+0xc3>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <set_audio_config+0xdf>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xddd(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_audio_config>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsi,%rdi
call   1060 <get_audio_bits@plt>
mov    %rax,%rbp
mov    %ebp,0x10(%rsp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
mov    $0xffffffff,%r14d
cmp    %ebp,0x10(%rsp)
jne    11fe <set_audio_config+0xae>
mov    %rbx,%rdi
call   1050 <get_audio_frq@plt>
mov    %eax,%ebp
mov    %eax,0xc(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
cmp    0xc(%rsp),%ebp
jne    11fe <set_audio_config+0xae>
mov    %rbx,%rdi
call   1070 <get_audio_channels@plt>
mov    %eax,%ebx
mov    %eax,0x14(%rsp)
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
lea    0x14(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
cmp    0x14(%rsp),%ebx
jne    11fe <set_audio_config+0xae>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe0c(%rip),%rdi
mov    %ebx,%ecx
call   1030 <printf@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SNDCTL_DSP_SETFMT = global i32 0
@SOUND_PCM_WRITE_RATE = global i32 0
@SNDCTL_DSP_CHANNELS = global i32 0
@.str = [26 x i8] c"Configuration : %d %d %d\0A\00"
define i32 @set_audio_config(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
%11 = call i64 @get_audio_bits(i32* %10)
%12 = trunc i64 %11 to i32
store i32 %12, i32* %7
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = load i32, i32* @SNDCTL_DSP_SETFMT
%15 = call i32 @ioctl(i32 %13, i32 %14, i32* %7)
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 -1, i32* %3
br label %45
20: ; preds = %2
%21 = load i32*, i32** %5
%22 = call i32 @get_audio_frq(i32* %21)
store i32 %22, i32* %8
store i32 %22, i32* %6
%23 = load i32, i32* %4
%24 = load i32, i32* @SOUND_PCM_WRITE_RATE
%25 = call i32 @ioctl(i32 %23, i32 %24, i32* %8)
%26 = load i32, i32* %6
%27 = load i32, i32* %8
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 -1, i32* %3
br label %45
30: ; preds = %20
%31 = load i32*, i32** %5
%32 = call i32 @get_audio_channels(i32* %31)
store i32 %32, i32* %9
store i32 %32, i32* %6
%33 = load i32, i32* %4
%34 = load i32, i32* @SNDCTL_DSP_CHANNELS
%35 = call i32 @ioctl(i32 %33, i32 %34, i32* %9)
%36 = load i32, i32* %6
%37 = load i32, i32* %9
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %30
store i32 -1, i32* %3
br label %45
40: ; preds = %30
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %42, i32 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %40, %39, %29, %19
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@SNDCTL_DSP_SETFMT = global i32 0
@SOUND_PCM_WRITE_RATE = global i32 0
@SNDCTL_DSP_CHANNELS = global i32 0
@.str = [26 x i8] c"Configuration : %d %d %d\0A\00"
define i32 @set_audio_config(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i64 @get_audio_bits(i32* %1)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %3
%11 = load i32, i32* @SNDCTL_DSP_SETFMT
%12 = call i32 @ioctl(i32 %0, i32 %11, i32* %3)
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, %10
br i1 %14, label %15, label %31
15: ; preds = %2
%16 = call i32 @get_audio_frq(i32* %1)
store i32 %16, i32* %4
%17 = load i32, i32* @SOUND_PCM_WRITE_RATE
%18 = call i32 @ioctl(i32 %0, i32 %17, i32* %4)
%19 = load i32, i32* %4
%20 = icmp eq i32 %16, %19
br i1 %20, label %21, label %31
21: ; preds = %15
%22 = call i32 @get_audio_channels(i32* %1)
store i32 %22, i32* %5
%23 = load i32, i32* @SNDCTL_DSP_CHANNELS
%24 = call i32 @ioctl(i32 %0, i32 %23, i32* %5)
%25 = load i32, i32* %5
%26 = icmp eq i32 %22, %25
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29, i32 %22)
br label %31
31: ; preds = %21, %15, %2, %27
%32 = phi i32 [ 0, %27 ], [ -1, %2 ], [ -1, %15 ], [ -1, %21 ]
ret i32 %32
}