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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SNDCTL_DSP_GETODELAY;
int /*<<< orphan*/ SNDCTL_DSP_SAMPLESIZE;
int /*<<< orphan*/ SNDCTL_DSP_SPEED;
int /*<<< orphan*/ SNDCTL_DSP_STEREO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ memset(short *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, short *, int);
int main(void) {
  short buf[256 * 2 * 100];
  int hifi, precision = 8, stereo = 1, rate = 8000, odelay, old = 0x7ffffff, x;
  hifi = open("/dev/dsp", O_WRONLY);
  if (hifi < 0 || ioctl(hifi, SNDCTL_DSP_SAMPLESIZE, &precision) == -1 ||
      ioctl(hifi, SNDCTL_DSP_STEREO, &stereo) == -1 ||
      ioctl(hifi, SNDCTL_DSP_SPEED, &rate) == -1) {
    fprintf(stderr, "Unable to open sound device\n");
    return 3;
  }
  memset(buf, 0, sizeof(buf));
  write(hifi, buf, sizeof(buf));
  for (x = 0;; x++) {
    if (ioctl(hifi, SNDCTL_DSP_GETODELAY, &odelay) < 0) {
      perror("ioctl");
      return 4;
    }
    if (old != odelay) {
      printf("%c %10d %10d\n", old < odelay ? '*' : ' ', odelay, odelay % 256);
      old = odelay;
    }
    if (odelay == 0)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x19040,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x8,-0x19018(%rbp)
movl   $0x1,-0x1901c(%rbp)
movl   $0x1f40,-0x19020(%rbp)
movl   $0x7ffffff,-0x19028(%rbp)
ff ff 07
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x19014(%rbp)
cmpl   $0x0,-0x19014(%rbp)
jl     123e <main+0xce>
mov    -0x19014(%rbp),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    -0x19018(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     123e <main+0xce>
mov    -0x19014(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    -0x1901c(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     123e <main+0xce>
mov    -0x19014(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    -0x19020(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    125f <main+0xef>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1377 <main+0x207>
lea    -0x19010(%rbp),%rdi
xor    %esi,%esi
mov    $0x19000,%edx
call   1050 <memset@plt>
mov    -0x19014(%rbp),%edi
lea    -0x19010(%rbp),%rsi
mov    $0x19000,%edx
call   1030 <write@plt>
movl   $0x0,-0x1902c(%rbp)
mov    -0x19014(%rbp),%edi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    -0x19024(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%eax
jge    12cf <main+0x15f>
lea    0xd68(%rip),%rdi
call   1090 <perror@plt>
movl   $0x4,-0x4(%rbp)
jmp    1377 <main+0x207>
mov    -0x19028(%rbp),%eax
cmp    -0x19024(%rbp),%eax
je     1345 <main+0x1d5>
mov    -0x19028(%rbp),%edx
mov    -0x19024(%rbp),%esi
mov    $0x20,%eax
mov    $0x2a,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
mov    %al,-0x19031(%rbp)
mov    -0x19024(%rbp),%eax
mov    %eax,-0x19030(%rbp)
mov    -0x19024(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x19031(%rbp),%al
mov    %edx,%ecx
mov    -0x19030(%rbp),%edx
lea    0xcfb(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x19024(%rbp),%eax
mov    %eax,-0x19028(%rbp)
cmpl   $0x0,-0x19024(%rbp)
jne    1357 <main+0x1e7>
jmp    1370 <main+0x200>
jmp    135c <main+0x1ec>
mov    -0x1902c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1902c(%rbp)
jmp    1293 <main+0x123>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x19040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x19018,%rsp
movl   $0x8,0xc(%rsp)
movl   $0x1,0x8(%rsp)
movl   $0x1f40,0x4(%rsp)
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     12a9 <main+0x139>
mov    %eax,%ebx
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0x139>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0x139>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0x139>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x19000,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x19000,%edx
call   1030 <write@plt>
mov    $0x7ffffff,%ebp
mov    0x2d9f(%rip),%r12
mov    %rsp,%r14
mov    $0x2a,%r13d
lea    0xddb(%rip),%r15
jmp    1264 <main+0xf4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %ebp,%ebp
je     12d5 <main+0x165>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <ioctl@plt>
test   %eax,%eax
js     12d9 <main+0x169>
mov    (%rsp),%edx
cmp    %edx,%ebp
je     1260 <main+0xf0>
lea    0xff(%rdx),%eax
test   %edx,%edx
cmovns %edx,%eax
and    $0xffffff00,%eax
mov    %edx,%ecx
sub    %eax,%ecx
cmp    %edx,%ebp
mov    $0x20,%esi
cmovl  %r13d,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    (%rsp),%ebp
jmp    1260 <main+0xf0>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x3,%eax
add    $0x19018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    12c3 <main+0x153>
lea    0xd46(%rip),%rdi
call   1090 <perror@plt>
mov    $0x4,%eax
jmp    12c3 <main+0x153>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/dsp\00"
@O_WRONLY = global i32 0
@SNDCTL_DSP_SAMPLESIZE = global i32 0
@SNDCTL_DSP_STEREO = global i32 0
@SNDCTL_DSP_SPEED = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Unable to open sound device\0A\00"
@SNDCTL_DSP_GETODELAY = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [14 x i8] c"%c %10d %10d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [51200 x i16]
%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* %1
store i32 8, i32* %4
store i32 1, i32* %5
store i32 8000, i32* %6
store i32 134217727, i32* %8
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %0
%15 = load i32, i32* %3
%16 = load i32, i32* @SNDCTL_DSP_SAMPLESIZE
%17 = call i32 @ioctl(i32 %15, i32 %16, i32* %4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %29, label %19
19: ; preds = %14
%20 = load i32, i32* %3
%21 = load i32, i32* @SNDCTL_DSP_STEREO
%22 = call i32 @ioctl(i32 %20, i32 %21, i32* %5)
%23 = icmp eq i32 %22, -1
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = load i32, i32* @SNDCTL_DSP_SPEED
%27 = call i32 @ioctl(i32 %25, i32 %26, i32* %6)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %24, %19, %14, %0
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %1
br label %70
32: ; preds = %24
%33 = getelementptr inbounds [51200 x i16], [51200 x i16]* %2, i64 0, i64 0
%34 = call i32 @memset(i16* %33, i32 0, i32 102400)
%35 = load i32, i32* %3
%36 = getelementptr inbounds [51200 x i16], [51200 x i16]* %2, i64 0, i64 0
%37 = call i32 @write(i32 %35, i16* %36, i32 102400)
store i32 0, i32* %9
br label %38
38: ; preds = %66, %32
%39 = load i32, i32* %3
%40 = load i32, i32* @SNDCTL_DSP_GETODELAY
%41 = call i32 @ioctl(i32 %39, i32 %40, i32* %7)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 4, i32* %1
br label %70
45: ; preds = %38
%46 = load i32, i32* %8
%47 = load i32, i32* %7
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %61
49: ; preds = %45
%50 = load i32, i32* %8
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
%53 = zext i1 %52 to i64
%54 = select i1 %52, i32 42, i32 32
%55 = trunc i32 %54 to i8
%56 = load i32, i32* %7
%57 = load i32, i32* %7
%58 = srem i32 %57, 256
%59 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8 signext %55, i32 %56, i32 %58)
%60 = load i32, i32* %7
store i32 %60, i32* %8
br label %61
61: ; preds = %49, %45
%62 = load i32, i32* %7
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %61
br label %69
65: ; preds = %61
br label %66
66: ; preds = %65
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %38
69: ; preds = %64
store i32 0, i32* %1
br label %70
70: ; preds = %69, %43, %29
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/dsp\00"
@O_WRONLY = global i32 0
@SNDCTL_DSP_SAMPLESIZE = global i32 0
@SNDCTL_DSP_STEREO = global i32 0
@SNDCTL_DSP_SPEED = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Unable to open sound device\0A\00"
@SNDCTL_DSP_GETODELAY = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [14 x i8] c"%c %10d %10d\0A\00"
define i32 @main() {
%1 = alloca [51200 x i16]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [51200 x i16]* %1 to i8*
%7 = bitcast i32* %2 to i8*
store i32 8, i32* %2
%8 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 8000, i32* %4
%10 = bitcast i32* %5 to i8*
%11 = load i32, i32* @O_WRONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %0
%15 = load i32, i32* @SNDCTL_DSP_SAMPLESIZE
%16 = call i32 @ioctl(i32 %12, i32 %15, i32* %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %26, label %18
18: ; preds = %14
%19 = load i32, i32* @SNDCTL_DSP_STEREO
%20 = call i32 @ioctl(i32 %12, i32 %19, i32* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* @SNDCTL_DSP_SPEED
%24 = call i32 @ioctl(i32 %12, i32 %23, i32* %4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %22, %18, %14, %0
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %52
29: ; preds = %22
%30 = getelementptr inbounds [51200 x i16], [51200 x i16]* %1, i64 0, i64 0
%31 = call i32 @memset(i16* %30, i32 0, i32 102400)
%32 = call i32 @write(i32 %12, i16* %30, i32 102400)
br label %33
33: ; preds = %49, %29
%34 = phi i32 [ 134217727, %29 ], [ %50, %49 ]
%35 = load i32, i32* @SNDCTL_DSP_GETODELAY
%36 = call i32 @ioctl(i32 %12, i32 %35, i32* %5)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %52
40: ; preds = %33
%41 = load i32, i32* %5
%42 = icmp eq i32 %34, %41
br i1 %42, label %49, label %43
43: ; preds = %40
%44 = icmp slt i32 %34, %41
%45 = select i1 %44, i8 42, i8 32
%46 = srem i32 %41, 256
%47 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8 signext %45, i32 %41, i32 %46)
%48 = load i32, i32* %5
br label %49
49: ; preds = %43, %40
%50 = phi i32 [ %48, %43 ], [ %34, %40 ]
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %33
52: ; preds = %49, %38, %26
%53 = phi i32 [ 3, %26 ], [ 4, %38 ], [ 0, %49 ]
ret i32 %53
}