#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SNDCTL_DSP_RESET;
int /*<<< orphan*/ SNDCTL_DSP_STEREO;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, int *, int);
int write(int, int *, int);
int main(int argc, char *argv[]) {
  int file_adc, file_dac;
  static int buffer[1536];
  int ret;
  file_adc = open("/dev/dsp", O_RDONLY, 0);
  file_dac = open("/dev/dsp", O_WRONLY, 0);
  if (file_adc == 0 || file_dac == 0) {
    perror("/dev/dsp");
    printf("problem in sound\n");
  } else {
    int mode;
    ioctl(file_adc, SNDCTL_DSP_RESET, &ret);
    mode = 2;
    ioctl(file_adc, SNDCTL_DSP_STEREO, &mode);
    mode = 2;
    ioctl(file_dac, SNDCTL_DSP_STEREO, &mode);
    while (1) {
      int size;
      int wsize;
      size = read(file_adc, buffer, 1536);
      if (size != 0) {
        wsize = write(file_dac, buffer, size);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11be <main+0x5e>
cmpl   $0x0,-0x18(%rbp)
jne    11db <main+0x7b>
lea    0xe3b(%rip),%rdi
call   1080 <perror@plt>
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    1263 <main+0x103>
mov    -0x14(%rbp),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1050 <ioctl@plt>
movl   $0x2,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
movl   $0x2,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x14(%rbp),%edi
lea    0x2e2e(%rip),%rsi
mov    $0x600,%edx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     125e <main+0xfe>
mov    -0x18(%rbp),%edi
mov    -0x24(%rbp),%edx
lea    0x2e0a(%rip),%rsi
call   1030 <write@plt>
mov    %eax,-0x28(%rbp)
jmp    1228 <main+0xc8>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rbp
mov    %rbp,%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %edx,%edx
call   1070 <open@plt>
test   %ebx,%ebx
je     1212 <main+0xb2>
mov    %eax,%r14d
test   %eax,%eax
je     1212 <main+0xb2>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
movl   $0x2,(%rsp)
mov    0x2e24(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rsp,%r15
mov    %ebx,%edi
mov    %r15,%rdx
call   1050 <ioctl@plt>
movl   $0x2,(%rsp)
mov    0x0(%rbp),%esi
mov    %r14d,%edi
mov    %r15,%rdx
call   1050 <ioctl@plt>
lea    0x2e70(%rip),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x600,%edx
call   1060 <read@plt>
test   %eax,%eax
je     11f0 <main+0x90>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    11f0 <main+0x90>
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.buffer = internal global [1536 x i32] zeroinitializer
@.str = [9 x i8] c"/dev/dsp\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [18 x i8] c"problem in sound\0A\00"
@SNDCTL_DSP_RESET = global i32 0
@SNDCTL_DSP_STEREO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14, i32 0)
store i32 %15, i32* %7
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %2
%22 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %44
24: ; preds = %18
%25 = load i32, i32* %6
%26 = load i32, i32* @SNDCTL_DSP_RESET
%27 = call i32 @ioctl(i32 %25, i32 %26, i32* %8)
store i32 2, i32* %9
%28 = load i32, i32* %6
%29 = load i32, i32* @SNDCTL_DSP_STEREO
%30 = call i32 @ioctl(i32 %28, i32 %29, i32* %9)
store i32 2, i32* %9
%31 = load i32, i32* %7
%32 = load i32, i32* @SNDCTL_DSP_STEREO
%33 = call i32 @ioctl(i32 %31, i32 %32, i32* %9)
br label %34
34: ; preds = %24, %43
%35 = load i32, i32* %6
%36 = call i32 @read(i32 %35, i32* getelementptr inbounds ([1536 x i32], [1536 x i32]* @main.buffer, i64 0, i64 0), i32 1536)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* %7
%41 = load i32, i32* %10
%42 = call i32 @write(i32 %40, i32* getelementptr inbounds ([1536 x i32], [1536 x i32]* @main.buffer, i64 0, i64 0), i32 %41)
store i32 %42, i32* %11
br label %43
43: ; preds = %39, %34
br label %34
44: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@main.buffer = internal global [1536 x i32] zeroinitializer
@.str = [9 x i8] c"/dev/dsp\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@SNDCTL_DSP_RESET = global i32 0
@SNDCTL_DSP_STEREO = global i32 0
@str = [17 x i8] c"problem in sound\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = load i32, i32* @O_WRONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8, i32 0)
%10 = icmp eq i32 %7, 0
%11 = icmp eq i32 %9, 0
%12 = or i1 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
ret i32 0
16: ; preds = %2
%17 = bitcast i32* %4 to i8*
%18 = load i32, i32* @SNDCTL_DSP_RESET
%19 = call i32 @ioctl(i32 %7, i32 %18, i32* %3)
store i32 2, i32* %4
%20 = load i32, i32* @SNDCTL_DSP_STEREO
%21 = call i32 @ioctl(i32 %7, i32 %20, i32* %4)
store i32 2, i32* %4
%22 = load i32, i32* @SNDCTL_DSP_STEREO
%23 = call i32 @ioctl(i32 %9, i32 %22, i32* %4)
br label %24
24: ; preds = %29, %16
%25 = call i32 @read(i32 %7, i32* getelementptr inbounds ([1536 x i32], [1536 x i32]* @main.buffer, i64 0, i64 0), i32 1536)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 @write(i32 %9, i32* getelementptr inbounds ([1536 x i32], [1536 x i32]* @main.buffer, i64 0, i64 0), i32 %25)
br label %29
29: ; preds = %27, %24
br label %24
}