#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 */

/* Variables and functions */
int AFMT_S16_LE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SNDCTL_DSP_CHANNELS;
int /*<<< orphan*/ SNDCTL_DSP_SETFMT;
int /*<<< orphan*/ SNDCTL_DSP_SPEED;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int record_init(int format, int channels, int speed) {
  int audio_fd;
  if ((audio_fd = open("/dev/dsp", O_RDONLY, 0)) == -1) {
    perror("/dev/dsp");
    exit(1);
  }
  if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format) == -1) {
    perror("SNDCTL_DSP_SETFMT");
    exit(1);
  }
  if (format != AFMT_S16_LE) {
    fprintf(stderr, "%s\n",
            "S16LE format is not supported by your device, exiting.");
    exit(1);
  }
  if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
    perror("SNDCTL_DSP_CHANNELS");
    exit(1);
  }
  if (channels != 1) {
    fprintf(stderr, "%s\n", "Mono is not supported by your device, exiting.");
    exit(1);
  }
  if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &speed) == -1) {
    perror("SNDCTL_DSP_SPEED");
    exit(1);
  }
  if (speed != 8000) {
    fprintf(stderr, "%s\n",
            "8000Hz sample rate is not supported by your device, exiting.");
    exit(1);
  }
  return audio_fd;
}


x86 assembly (clang, -O0):
<record_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    119a <record_init+0x4a>
lea    0xe75(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11ce <record_init+0x7e>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%eax
je     1206 <record_init+0xb6>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
lea    0xe28(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    123a <record_init+0xea>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
je     126a <record_init+0x11a>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
lea    0xe0f(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    129e <record_init+0x14e>
lea    0xe0a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x1f40,-0xc(%rbp)
je     12d1 <record_init+0x181>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
lea    0xde8(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<record_init>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0xc(%rsp)
mov    %esi,0x8(%rsp)
mov    %edx,0x4(%rsp)
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11f5 <record_init+0xa5>
mov    %eax,%ebx
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11fe <record_init+0xae>
mov    0xc(%rsp),%eax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%eax
jne    1207 <record_init+0xb7>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1220 <record_init+0xd0>
cmpl   $0x1,0x8(%rsp)
jne    1229 <record_init+0xd9>
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1242 <record_init+0xf2>
cmpl   $0x1f40,0x4(%rsp)
jne    1258 <record_init+0x108>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe04(%rip),%rdi
jmp    1249 <record_init+0xf9>
lea    0xe04(%rip),%rdi
jmp    1249 <record_init+0xf9>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
lea    0xe01(%rip),%rdx
jmp    126f <record_init+0x11f>
lea    0xe2f(%rip),%rdi
jmp    1249 <record_init+0xf9>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
lea    0xe2a(%rip),%rdx
jmp    126f <record_init+0x11f>
lea    0xe50(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
lea    0xe3b(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/dsp\00"
@O_RDONLY = global i32 0
@SNDCTL_DSP_SETFMT = global i32 0
@.str.1 = [18 x i8] c"SNDCTL_DSP_SETFMT\00"
@AFMT_S16_LE = global i32 0
@stderr = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [55 x i8] c"S16LE format is not supported by your device, exiting.\00"
@SNDCTL_DSP_CHANNELS = global i32 0
@.str.4 = [20 x i8] c"SNDCTL_DSP_CHANNELS\00"
@.str.5 = [47 x i8] c"Mono is not supported by your device, exiting.\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.6 = [17 x i8] c"SNDCTL_DSP_SPEED\00"
@.str.7 = [61 x i8] c"8000Hz sample rate is not supported by your device, exiting.\00"
define i32 @record_init(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8, i32 0)
store i32 %9, i32* %7
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = load i32, i32* %7
%16 = load i32, i32* @SNDCTL_DSP_SETFMT
%17 = call i32 @ioctl(i32 %15, i32 %16, i32* %4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* %4
%24 = load i32, i32* @AFMT_S16_LE
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
%31 = load i32, i32* %7
%32 = load i32, i32* @SNDCTL_DSP_CHANNELS
%33 = call i32 @ioctl(i32 %31, i32 %32, i32* %5)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %30
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %38
%46 = load i32, i32* %7
%47 = load i32, i32* @SNDCTL_DSP_SPEED
%48 = call i32 @ioctl(i32 %46, i32 %47, i32* %6)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %45
%54 = load i32, i32* %6
%55 = icmp ne i32 %54, 8000
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %53
%61 = load i32, i32* %7
ret i32 %61
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/dsp\00"
@O_RDONLY = global i32 0
@SNDCTL_DSP_SETFMT = global i32 0
@.str.1 = [18 x i8] c"SNDCTL_DSP_SETFMT\00"
@AFMT_S16_LE = global i32 0
@stderr = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [55 x i8] c"S16LE format is not supported by your device, exiting.\00"
@SNDCTL_DSP_CHANNELS = global i32 0
@.str.4 = [20 x i8] c"SNDCTL_DSP_CHANNELS\00"
@.str.5 = [47 x i8] c"Mono is not supported by your device, exiting.\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.6 = [17 x i8] c"SNDCTL_DSP_SPEED\00"
@.str.7 = [61 x i8] c"8000Hz sample rate is not supported by your device, exiting.\00"
define i32 @record_init(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = load i32, i32* @SNDCTL_DSP_SETFMT
%15 = call i32 @ioctl(i32 %8, i32 %14, i32* %4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = load i32, i32* %4
%22 = load i32, i32* @AFMT_S16_LE
%23 = icmp eq i32 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i32, i32* @SNDCTL_DSP_CHANNELS
%30 = call i32 @ioctl(i32 %8, i32 %29, i32* %5)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 1
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35
%43 = load i32, i32* @SNDCTL_DSP_SPEED
%44 = call i32 @ioctl(i32 %8, i32 %43, i32* %6)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %42
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, 8000
br i1 %51, label %56, label %52
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %49
ret i32 %8
}