#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*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wwviaudio_add_sound(int /*<<< orphan*/);
int wwviaudio_get_sound_device();
int wwviaudio_initialize_portaudio(int, int);
int /*<<< orphan*/ wwviaudio_list_devices();
int wwviaudio_read_ogg_clip(int /*<<< orphan*/, char *);
int /*<<< orphan*/ wwviaudio_set_sound_device(int);
int main(int argc, char *argv[]) {
  int rc;
  char *sound_device_str;
  int sound_device = -1;
  char *sound_file = "share/snis/sounds/red-alert.ogg";
  printf("Space Nerds In Space audio test program.\n");
  printf("How to use this program:\n");
  printf("Type the following:\n");
  printf("  make snis_test_audio\n");
  printf("  ./snis_test_audio\n\n");
  printf("Or, if you want to try a sound device other than the default, such "
         "as device 6:\n\n");
  printf("  ./snis_test_audio 6\n\n");
  printf("The device numbers should be listed below.\n\n\n");
  if (argc > 1) {
    sound_device_str = argv[1];
    rc = sscanf(sound_device_str, "%d", &sound_device);
    if (rc != 1) {
      sound_device = -1;
    }
  }
  if (sound_device >= 0) {
    printf("Manually setting sound device to %d\n", sound_device);
    wwviaudio_set_sound_device(sound_device);
  }
  rc = wwviaudio_initialize_portaudio(10, 10);
  printf("wwviaudio_initialize_portaudio returned %d\n", rc);
  if (rc != 0) {
    return rc;
  }
  sound_device = wwviaudio_get_sound_device();
  rc = wwviaudio_read_ogg_clip(0, sound_file);
  if (rc != 0) {
    printf("Failed to read %s\n", sound_file);
    exit(1);
  }
  wwviaudio_list_devices();
  printf("Attempting to play sound '%s' to device %d... ", sound_file,
         sound_device);
  fflush(stdout);
  wwviaudio_add_sound(0);
  sleep(1);
  printf("...finished attempting to play sound\n");
  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)
movl   $0xffffffff,-0x24(%rbp)
lea    0xe2c(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    128b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xed6(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   10a0 <sscanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     1286 <main+0xd6>
movl   $0xffffffff,-0x24(%rbp)
jmp    128b <main+0xdb>
cmpl   $0x0,-0x24(%rbp)
jl     12ae <main+0xfe>
mov    -0x24(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x24(%rbp),%edi
call   1060 <wwviaudio_set_sound_device@plt>
mov    $0xa,%esi
mov    %esi,%edi
call   10b0 <wwviaudio_initialize_portaudio@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     12e3 <main+0x133>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1371 <main+0x1c1>
mov    $0x0,%al
call   1030 <wwviaudio_get_sound_device@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rsi
xor    %edi,%edi
call   1050 <wwviaudio_read_ogg_clip@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1321 <main+0x171>
mov    -0x30(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1040 <wwviaudio_list_devices@plt>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
xor    %edi,%edi
call   1070 <wwviaudio_add_sound@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xedf(%rip),%rdi
call   1050 <puts@plt>
lea    0xefc(%rip),%rdi
call   1050 <puts@plt>
lea    0xf09(%rip),%rdi
call   1050 <puts@plt>
lea    0xf11(%rip),%rdi
call   1050 <puts@plt>
lea    0xf1c(%rip),%rdi
call   1050 <puts@plt>
lea    0xf25(%rip),%rdi
call   1050 <puts@plt>
lea    0xf6a(%rip),%rdi
call   1050 <puts@plt>
lea    0xf75(%rip),%rdi
call   1050 <puts@plt>
cmp    $0x2,%ebp
jl     1278 <main+0xb8>
mov    0x8(%rbx),%rdi
lea    0xde0(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    1270 <main+0xb0>
mov    0x4(%rsp),%esi
test   %esi,%esi
js     1278 <main+0xb8>
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x4(%rsp),%edi
call   1070 <wwviaudio_set_sound_device@plt>
jmp    1278 <main+0xb8>
movl   $0xffffffff,0x4(%rsp)
ff
mov    $0xa,%edi
mov    $0xa,%esi
call   10c0 <wwviaudio_initialize_portaudio@plt>
mov    %eax,%ebx
lea    0xdb8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
test   %ebx,%ebx
jne    1305 <main+0x145>
xor    %eax,%eax
call   1030 <wwviaudio_get_sound_device@plt>
mov    %eax,0x4(%rsp)
lea    0xd51(%rip),%rsi
xor    %edi,%edi
call   1060 <wwviaudio_read_ogg_clip@plt>
test   %eax,%eax
jne    130e <main+0x14e>
xor    %eax,%eax
call   1040 <wwviaudio_list_devices@plt>
mov    0x4(%rsp),%edx
lea    0xdbb(%rip),%rdi
lea    0xd2d(%rip),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
xor    %edi,%edi
call   1080 <wwviaudio_add_sound@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
lea    0xecd(%rip),%rdi
call   1050 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd5f(%rip),%rdi
lea    0xce4(%rip),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"share/snis/sounds/red-alert.ogg\00"
@.str.1 = [42 x i8] c"Space Nerds In Space audio test program.\0A\00"
@.str.2 = [26 x i8] c"How to use this program:\0A\00"
@.str.3 = [21 x i8] c"Type the following:\0A\00"
@.str.4 = [24 x i8] c" make snis_test_audio\0A\00"
@.str.5 = [22 x i8] c" ./snis_test_audio\0A\0A\00"
@.str.6 = [82 x i8] c"Or, if you want to try a sound device other than the default, such as device 6:\0A\0A\00"
@.str.7 = [24 x i8] c" ./snis_test_audio 6\0A\0A\00"
@.str.8 = [46 x i8] c"The device numbers should be listed below.\0A\0A\0A\00"
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [37 x i8] c"Manually setting sound device to %d\0A\00"
@.str.11 = [44 x i8] c"wwviaudio_initialize_portaudio returned %d\0A\00"
@.str.12 = [19 x i8] c"Failed to read %s\0A\00"
@.str.13 = [47 x i8] c"Attempting to play sound '%s' to device %d... \00"
@stdout = global i32 0
@.str.14 = [38 x i8] c"...finished attempting to play sound\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.6, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %30
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %8)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 -1, i32* %8
br label %29
29: ; preds = %28, %20
br label %30
30: ; preds = %29, %2
%31 = load i32, i32* %8
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32, i32* %8
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %8
%37 = call i32 @wwviaudio_set_sound_device(i32 %36)
br label %38
38: ; preds = %33, %30
%39 = call i32 @wwviaudio_initialize_portaudio(i32 10, i32 10)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %6
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = load i32, i32* %6
store i32 %45, i32* %3
br label %66
46: ; preds = %38
%47 = call i32 (...) @wwviaudio_get_sound_device()
store i32 %47, i32* %8
%48 = load i8*, i8** %9
%49 = call i32 @wwviaudio_read_ogg_clip(i32 0, i8* %48)
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %46
%53 = load i8*, i8** %9
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46
%57 = call i32 (...) @wwviaudio_list_devices()
%58 = load i8*, i8** %9
%59 = load i32, i32* %8
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.13, i64 0, i64 0), i8* %58, i32 %59)
%61 = load i32, i32* @stdout
%62 = call i32 @fflush(i32 %61)
%63 = call i32 @wwviaudio_add_sound(i32 0)
%64 = call i32 @sleep(i32 1)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %3
br label %66
66: ; preds = %56, %44
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [32 x i8] c"share/snis/sounds/red-alert.ogg\00"
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [37 x i8] c"Manually setting sound device to %d\0A\00"
@.str.11 = [44 x i8] c"wwviaudio_initialize_portaudio returned %d\0A\00"
@.str.12 = [19 x i8] c"Failed to read %s\0A\00"
@.str.13 = [47 x i8] c"Attempting to play sound '%s' to device %d... \00"
@stdout = global i32 0
@str = [41 x i8] c"Space Nerds In Space audio test program.\00"
@str.15 = [25 x i8] c"How to use this program:\00"
@str.16 = [20 x i8] c"Type the following:\00"
@str.17 = [23 x i8] c" make snis_test_audio\00"
@str.18 = [21 x i8] c" ./snis_test_audio\0A\00"
@str.19 = [81 x i8] c"Or, if you want to try a sound device other than the default, such as device 6:\0A\00"
@str.20 = [23 x i8] c" ./snis_test_audio 6\0A\00"
@str.21 = [45 x i8] c"The device numbers should be listed below.\0A\0A\00"
@str.22 = [37 x i8] c"...finished attempting to play sound\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.15, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.17, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.18, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.19, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.20, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.21, i64 0, i64 0))
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %27
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %3)
%18 = icmp eq i32 %17, 1
br i1 %18, label %20, label %19
19: ; preds = %14
store i32 -1, i32* %3
br label %27
20: ; preds = %14
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %21)
%25 = load i32, i32* %3
%26 = call i32 @wwviaudio_set_sound_device(i32 %25)
br label %27
27: ; preds = %2, %19, %23, %20
%28 = call i32 @wwviaudio_initialize_portaudio(i32 10, i32 10)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0), i32 %28)
%30 = icmp eq i32 %28, 0
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = call i32 (...) @wwviaudio_get_sound_device()
store i32 %32, i32* %3
%33 = call i32 @wwviaudio_read_ogg_clip(i32 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = call i32 (...) @wwviaudio_list_devices()
%40 = load i32, i32* %3
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @stdout
%43 = call i32 @fflush(i32 %42)
%44 = call i32 @wwviaudio_add_sound(i32 0)
%45 = call i32 @sleep(i32 1)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.22, i64 0, i64 0))
br label %47
47: ; preds = %27, %38
ret i32 %28
}