#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*/ O_WRONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ ioctl(int, int, int *);
int open(char *, int /*<<< orphan*/);
scalar_t__ play_file(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ set_audio_config(int, int /*<<< orphan*/ *);
int main(int ac, char *av[]) {
  FILE *fd_file;
  int fd_audio, fd_audio2;
  int i, loop, ssi_index, out_src, val;
  int err = 0;
  char rep[32];
  char sounddevice[32];
  printf("Hi... \n");
  if (ac == 1) {
    printf("main <ssi_nb> <soundfile.wav> <outsrc> [nb_loops]\n Plays the file "
           "to /dev/dspX (uncompressed data)\n");
    printf("ssi_nb : 1 for SSI1 ... \n");
    printf("outsrc : 0: earpiece, 1:handsfree, 2:headset, 3: line out \n");
    return 0;
  }
  out_src = atoi(av[3]);
  if (ac == 5)
    loop = atoi(av[4]);
  else
    loop = 1;
  if ((fd_file = fopen(av[2], "r")) <= 0) {
    err++;
    goto _err_file_not_found;
  }
  if ((fd_audio = open("/dev/sound/dsp", O_WRONLY)) < 0) {
    printf("Error opening /dev/sound/dsp");
    err++;
    goto _err_drv_open;
  }
  ssi_index = atoi(av[1]);
  if (ssi_index == 2) {
    fd_audio2 = fd_audio;
    if ((fd_audio = open("/dev/sound/dsp1", O_WRONLY)) < 0) {
      printf("Error opening /dev/sound/dsp1");
      err++;
      goto _err_drv_open2;
    }
  }
  if (set_audio_config(fd_audio, fd_file) < 0) {
    printf("Bad format for file 1. ");
    printf("Do you want to continue ? (y/n) : ");
    scanf("%s", rep);
    err++;
    if (rep[0] != 'y')
      goto _err_fmt;
  }
  switch (out_src) {
  case 0:
    val = (1 << 21);
    if (ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xfa)),
              &val) < 0)
      err++;
    break;
  case 1:
    val = (1 << 5);
    if (ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xfa)),
              &val) < 0)
      err++;
    break;
  case 2:
    val = (1 << 0);
    if (ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xfa)),
              &val) < 0)
      err++;
    break;
  case 3:
    val = (1 << 4);
    if (ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xfa)),
              &val) < 0)
      err++;
    break;
  default:
    printf("Unknown out src, using the default one\n");
  }
  for (i = 0; i < loop; i++) {
    err += play_file(fd_audio, fd_file);
  }
  printf("************** Closing the device\n");
  fclose(fd_file);
  if (ssi_index == 2)
    close(fd_audio2);
  close(fd_audio);
  if (err)
    goto _end_err;
  printf("All tests passed with success\n");
  return 0;
_err_fmt:
  if (ssi_index == 2)
    close(fd_audio2);
_err_drv_open2:
  close(fd_audio);
_err_drv_open:
  fclose(fd_file);
_end_err:
  printf("Encountered %d errors\n", err);
  return err;
_err_file_not_found:
  printf("Error opening the file %s \n", av[2]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x38(%rbp)
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    120e <main+0x6e>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    155f <main+0x3bf>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x5,-0x8(%rbp)
jne    123d <main+0x9d>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    1244 <main+0xa4>
movl   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe7f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
ja     1274 <main+0xd4>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1542 <main+0x3a2>
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12b1 <main+0x111>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    151d <main+0x37d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jne    1313 <main+0x173>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    130e <main+0x16e>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1515 <main+0x375>
jmp    1313 <main+0x173>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <set_audio_config@plt>
cmp    $0x0,%rax
jge    1375 <main+0x1d5>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xdfa(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movsbl -0x60(%rbp),%eax
cmp    $0x79,%eax
je     1370 <main+0x1d0>
jmp    14fe <main+0x35e>
jmp    1375 <main+0x1d5>
mov    -0x30(%rbp),%eax
mov    %rax,-0x88(%rbp)
sub    $0x3,%rax
ja     145c <main+0x2bc>
mov    -0x88(%rbp),%rax
lea    0xc69(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x200000,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x34(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%eax
jge    13ca <main+0x22a>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    146a <main+0x2ca>
movl   $0x20,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x34(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%eax
jge    13f9 <main+0x259>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    146a <main+0x2ca>
movl   $0x1,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x34(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%eax
jge    1428 <main+0x288>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    146a <main+0x2ca>
movl   $0x10,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x34(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%eax
jge    1457 <main+0x2b7>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    146a <main+0x2ca>
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    14a4 <main+0x304>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <play_file@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1471 <main+0x2d1>
lea    0xcca(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x2,-0x2c(%rbp)
jne    14cd <main+0x32d>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x0,-0x38(%rbp)
je     14e4 <main+0x344>
jmp    1526 <main+0x386>
lea    0xcad(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    155f <main+0x3bf>
cmpl   $0x2,-0x2c(%rbp)
jne    1510 <main+0x370>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
jmp    1515 <main+0x375>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%esi
lea    0xc87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    155f <main+0x3bf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xef4(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebx
jne    11ff <main+0x4f>
lea    0xf51(%rip),%rdi
call   1030 <puts@plt>
lea    0xfa8(%rip),%rdi
call   1030 <puts@plt>
lea    0xfb5(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1400 <main+0x250>
mov    0x18(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r12d
mov    $0x1,%ebp
cmp    $0x5,%ebx
jne    1220 <main+0x70>
mov    0x20(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
lea    0xde5(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12ff <main+0x14f>
mov    %rax,%r13
mov    0x2d95(%rip),%rbx
mov    (%rbx),%esi
lea    0xdd4(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     1318 <main+0x168>
mov    %eax,%r15d
mov    0x8(%r14),%rdi
call   10d0 <atoi@plt>
mov    %r15d,%r14d
mov    %eax,0xc(%rsp)
cmp    $0x2,%eax
jne    128a <main+0xda>
mov    (%rbx),%esi
lea    0xdc3(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1328 <main+0x178>
mov    %r14d,%edi
mov    %r13,%rsi
call   1040 <set_audio_config@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    12d5 <main+0x125>
lea    0xdaa(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdb4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdc9(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <scanf@plt>
mov    $0x1,%ebx
cmpb   $0x79,0x10(%rsp)
jne    1338 <main+0x188>
cmp    $0x3,%r12d
ja     1361 <main+0x1b1>
mov    %r12d,%eax
lea    0xd17(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x200000,0x8(%rsp)
jmp    138b <main+0x1db>
mov    0x10(%r14),%rsi
lea    0xd98(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1400 <main+0x250>
lea    0xcf3(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    134f <main+0x19f>
lea    0xd00(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1347 <main+0x197>
cmpl   $0x2,0xc(%rsp)
jne    1347 <main+0x197>
mov    %r15d,%edi
call   1090 <close@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    $0x1,%ebx
jmp    13f0 <main+0x240>
lea    0xd9d(%rip),%rdi
call   1030 <puts@plt>
jmp    13a2 <main+0x1f2>
movl   $0x20,0x8(%rsp)
jmp    138b <main+0x1db>
movl   $0x1,0x8(%rsp)
jmp    138b <main+0x1db>
movl   $0x10,0x8(%rsp)
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
mov    $0x60044dfa,%esi
call   1080 <ioctl@plt>
shr    $0x1f,%eax
add    %eax,%ebx
mov    0xc(%rsp),%r12d
test   %ebp,%ebp
jle    13c2 <main+0x212>
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r13,%rsi
call   1050 <play_file@plt>
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    13b0 <main+0x200>
lea    0xcfc(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
cmp    $0x2,%r12d
jne    13e4 <main+0x234>
mov    %r15d,%edi
call   1090 <close@plt>
mov    %r14d,%edi
call   1090 <close@plt>
test   %ebx,%ebx
je     1411 <main+0x261>
lea    0xc94(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xccf(%rip),%rdi
jmp    11f3 <main+0x43>

LLVM IR (-O0):
@.str = [8 x i8] c"Hi... \0A\00"
@.str.1 = [100 x i8] c"main <ssi_nb> <soundfile.wav> <outsrc> [nb_loops]\0A Plays the file to /dev/dspX (uncompressed data)\0A\00"
@.str.2 = [26 x i8] c"ssi_nb : 1 for SSI1 ... \0A\00"
@.str.3 = [60 x i8] c"outsrc : 0: earpiece, 1:handsfree, 2:headset, 3: line out \0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [15 x i8] c"/dev/sound/dsp\00"
@O_WRONLY = global i32 0
@.str.6 = [29 x i8] c"Error opening /dev/sound/dsp\00"
@.str.7 = [16 x i8] c"/dev/sound/dsp1\00"
@.str.8 = [30 x i8] c"Error opening /dev/sound/dsp1\00"
@.str.9 = [24 x i8] c"Bad format for file 1. \00"
@.str.10 = [35 x i8] c"Do you want to continue ? (y/n) : \00"
@.str.11 = [3 x i8] c"%s\00"
@.str.12 = [40 x i8] c"Unknown out src, using the default one\0A\00"
@.str.13 = [35 x i8] c"************** Closing the device\0A\00"
@.str.14 = [31 x i8] c"All tests passed with success\0A\00"
@.str.15 = [23 x i8] c"Encountered %d errors\0A\00"
@.str.16 = [28 x i8] c"Error opening the file %s \0A\00"
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
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [32 x i8]
%16 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %14
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %180
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %12
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 5
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 4
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %10
br label %37
36: ; preds = %24
store i32 1, i32* %10
br label %37
37: ; preds = %36, %31
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %6
%42 = icmp ule i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = load i32, i32* %14
%45 = add nsw i32 %44, 1
store i32 %45, i32* %14
br label %175
46: ; preds = %37
%47 = load i32, i32* @O_WRONLY
%48 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %47)
store i32 %48, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%52 = load i32, i32* %14
%53 = add nsw i32 %52, 1
store i32 %53, i32* %14
br label %168
54: ; preds = %46
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 @atoi(i8* %57)
store i32 %58, i32* %11
%59 = load i32, i32* %11
%60 = icmp eq i32 %59, 2
br i1 %60, label %61, label %71
61: ; preds = %54
%62 = load i32, i32* %7
store i32 %62, i32* %8
%63 = load i32, i32* @O_WRONLY
%64 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %63)
store i32 %64, i32* %7
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %61
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%68 = load i32, i32* %14
%69 = add nsw i32 %68, 1
store i32 %69, i32* %14
br label %165
70: ; preds = %61
br label %71
71: ; preds = %70, %54
%72 = load i32, i32* %7
%73 = load i32*, i32** %6
%74 = call i64 @set_audio_config(i32 %72, i32* %73)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %89
76: ; preds = %71
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0))
%79 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%80 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %79)
%81 = load i32, i32* %14
%82 = add nsw i32 %81, 1
store i32 %82, i32* %14
%83 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp ne i32 %85, 121
br i1 %86, label %87, label %88
87: ; preds = %76
br label %158
88: ; preds = %76
br label %89
89: ; preds = %88, %71
%90 = load i32, i32* %12
switch i32 %90, label %123 [
i32 0, label %91
i32 1, label %99
i32 2, label %107
i32 3, label %115
]
91: ; preds = %89
store i32 2097152, i32* %13
%92 = load i32, i32* %7
%93 = call i32 @ioctl(i32 %92, i32 1610894842, i32* %13)
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = load i32, i32* %14
%97 = add nsw i32 %96, 1
store i32 %97, i32* %14
br label %98
98: ; preds = %95, %91
br label %125
99: ; preds = %89
store i32 32, i32* %13
%100 = load i32, i32* %7
%101 = call i32 @ioctl(i32 %100, i32 1610894842, i32* %13)
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %99
%104 = load i32, i32* %14
%105 = add nsw i32 %104, 1
store i32 %105, i32* %14
br label %106
106: ; preds = %103, %99
br label %125
107: ; preds = %89
store i32 1, i32* %13
%108 = load i32, i32* %7
%109 = call i32 @ioctl(i32 %108, i32 1610894842, i32* %13)
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %107
%112 = load i32, i32* %14
%113 = add nsw i32 %112, 1
store i32 %113, i32* %14
br label %114
114: ; preds = %111, %107
br label %125
115: ; preds = %89
store i32 16, i32* %13
%116 = load i32, i32* %7
%117 = call i32 @ioctl(i32 %116, i32 1610894842, i32* %13)
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %115
%120 = load i32, i32* %14
%121 = add nsw i32 %120, 1
store i32 %121, i32* %14
br label %122
122: ; preds = %119, %115
br label %125
123: ; preds = %89
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %125
125: ; preds = %123, %122, %114, %106, %98
store i32 0, i32* %9
br label %126
126: ; preds = %138, %125
%127 = load i32, i32* %9
%128 = load i32, i32* %10
%129 = icmp slt i32 %127, %128
br i1 %129, label %130, label %141
130: ; preds = %126
%131 = load i32, i32* %7
%132 = load i32*, i32** %6
%133 = call i64 @play_file(i32 %131, i32* %132)
%134 = load i32, i32* %14
%135 = sext i32 %134 to i64
%136 = add nsw i64 %135, %133
%137 = trunc i64 %136 to i32
store i32 %137, i32* %14
br label %138
138: ; preds = %130
%139 = load i32, i32* %9
%140 = add nsw i32 %139, 1
store i32 %140, i32* %9
br label %126
141: ; preds = %126
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0))
%143 = load i32*, i32** %6
%144 = call i32 @fclose(i32* %143)
%145 = load i32, i32* %11
%146 = icmp eq i32 %145, 2
br i1 %146, label %147, label %150
147: ; preds = %141
%148 = load i32, i32* %8
%149 = call i32 @close(i32 %148)
br label %150
150: ; preds = %147, %141
%151 = load i32, i32* %7
%152 = call i32 @close(i32 %151)
%153 = load i32, i32* %14
%154 = icmp ne i32 %153, 0
br i1 %154, label %155, label %156
155: ; preds = %150
br label %171
156: ; preds = %150
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %3
br label %180
158: ; preds = %87
%159 = load i32, i32* %11
%160 = icmp eq i32 %159, 2
br i1 %160, label %161, label %164
161: ; preds = %158
%162 = load i32, i32* %8
%163 = call i32 @close(i32 %162)
br label %164
164: ; preds = %161, %158
br label %165
165: ; preds = %164, %66
%166 = load i32, i32* %7
%167 = call i32 @close(i32 %166)
br label %168
168: ; preds = %165, %50
%169 = load i32*, i32** %6
%170 = call i32 @fclose(i32* %169)
br label %171
171: ; preds = %168, %155
%172 = load i32, i32* %14
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0), i32 %172)
%174 = load i32, i32* %14
store i32 %174, i32* %3
br label %180
175: ; preds = %43
%176 = load i8**, i8*** %5
%177 = getelementptr inbounds i8*, i8** %176, i64 2
%178 = load i8*, i8** %177
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.16, i64 0, i64 0), i8* %178)
store i32 0, i32* %3
br label %180
180: ; preds = %175, %171, %156, %20
%181 = load i32, i32* %3
ret i32 %181
}

LLVM IR (-O2):
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [15 x i8] c"/dev/sound/dsp\00"
@O_WRONLY = global i32 0
@.str.6 = [29 x i8] c"Error opening /dev/sound/dsp\00"
@.str.7 = [16 x i8] c"/dev/sound/dsp1\00"
@.str.8 = [30 x i8] c"Error opening /dev/sound/dsp1\00"
@.str.9 = [24 x i8] c"Bad format for file 1. \00"
@.str.10 = [35 x i8] c"Do you want to continue ? (y/n) : \00"
@.str.11 = [3 x i8] c"%s\00"
@.str.15 = [23 x i8] c"Encountered %d errors\0A\00"
@.str.16 = [28 x i8] c"Error opening the file %s \0A\00"
@str = [7 x i8] c"Hi... \00"
@str.17 = [34 x i8] c"************** Closing the device\00"
@str.18 = [30 x i8] c"All tests passed with success\00"
@str.19 = [39 x i8] c"Unknown out src, using the default one\00"
@str.20 = [99 x i8] c"main <ssi_nb> <soundfile.wav> <outsrc> [nb_loops]\0A Plays the file to /dev/dspX (uncompressed data)\00"
@str.21 = [25 x i8] c"ssi_nb : 1 for SSI1 ... \00"
@str.22 = [59 x i8] c"outsrc : 0: earpiece, 1:handsfree, 2:headset, 3: line out \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%8 = icmp eq i32 %0, 1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @str.20, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.21, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.22, i64 0, i64 0))
br label %111
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp eq i32 %0, 5
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
br label %22
22: ; preds = %13, %18
%23 = phi i32 [ %21, %18 ], [ 1, %13 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i8*, i8** %24
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.16, i64 0, i64 0), i8* %29)
br label %111
31: ; preds = %22
%32 = load i32, i32* @O_WRONLY
%33 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %106
37: ; preds = %31
%38 = getelementptr inbounds i8*, i8** %1, i64 1
%39 = load i8*, i8** %38
%40 = tail call i32 @atoi(i8* %39)
%41 = icmp eq i32 %40, 2
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i32, i32* @O_WRONLY
%44 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %103
48: ; preds = %42, %37
%49 = phi i32 [ %44, %42 ], [ %33, %37 ]
%50 = tail call i64 @set_audio_config(i32 %49, i32* %26)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0))
%55 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %6)
%56 = load i8, i8* %6
%57 = icmp eq i8 %56, 121
br i1 %57, label %58, label %100
58: ; preds = %52, %48
%59 = phi i32 [ 1, %52 ], [ 0, %48 ]
switch i32 %16, label %76 [
i32 0, label %60
i32 1, label %64
i32 2, label %68
i32 3, label %72
]
60: ; preds = %58
store i32 2097152, i32* %3
%61 = call i32 @ioctl(i32 %49, i32 1610894842, i32* %3)
%62 = lshr i32 %61, 31
%63 = add nuw nsw i32 %62, %59
br label %78
64: ; preds = %58
store i32 32, i32* %3
%65 = call i32 @ioctl(i32 %49, i32 1610894842, i32* %3)
%66 = lshr i32 %65, 31
%67 = add nuw nsw i32 %66, %59
br label %78
68: ; preds = %58
store i32 1, i32* %3
%69 = call i32 @ioctl(i32 %49, i32 1610894842, i32* %3)
%70 = lshr i32 %69, 31
%71 = add nuw nsw i32 %70, %59
br label %78
72: ; preds = %58
store i32 16, i32* %3
%73 = call i32 @ioctl(i32 %49, i32 1610894842, i32* %3)
%74 = lshr i32 %73, 31
%75 = add nuw nsw i32 %74, %59
br label %78
76: ; preds = %58
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.19, i64 0, i64 0))
br label %78
78: ; preds = %72, %68, %64, %60, %76
%79 = phi i32 [ %59, %76 ], [ %63, %60 ], [ %67, %64 ], [ %71, %68 ], [ %75, %72 ]
%80 = icmp sgt i32 %23, 0
br i1 %80, label %81, label %89
81: ; preds = %78, %81
%82 = phi i32 [ %86, %81 ], [ %79, %78 ]
%83 = phi i32 [ %87, %81 ], [ 0, %78 ]
%84 = call i64 @play_file(i32 %49, i32* %26)
%85 = trunc i64 %84 to i32
%86 = add i32 %82, %85
%87 = add nuw nsw i32 %83, 1
%88 = icmp eq i32 %87, %23
br i1 %88, label %89, label %81
89: ; preds = %81, %78
%90 = phi i32 [ %79, %78 ], [ %86, %81 ]
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.17, i64 0, i64 0))
%92 = call i32 @fclose(i32* %26)
br i1 %41, label %93, label %95
93: ; preds = %89
%94 = call i32 @close(i32 %33)
br label %95
95: ; preds = %93, %89
%96 = call i32 @close(i32 %49)
%97 = icmp eq i32 %90, 0
br i1 %97, label %98, label %108
98: ; preds = %95
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.18, i64 0, i64 0))
br label %111
100: ; preds = %52
br i1 %41, label %101, label %103
101: ; preds = %100
%102 = call i32 @close(i32 %33)
br label %103
103: ; preds = %100, %101, %46
%104 = phi i32 [ %44, %46 ], [ %49, %101 ], [ %49, %100 ]
%105 = call i32 @close(i32 %104)
br label %106
106: ; preds = %103, %35
%107 = call i32 @fclose(i32* %26)
br label %108
108: ; preds = %95, %106
%109 = phi i32 [ 1, %106 ], [ %90, %95 ]
%110 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0), i32 %109)
br label %111
111: ; preds = %28, %108, %98, %9
%112 = phi i32 [ 0, %9 ], [ 0, %28 ], [ %109, %108 ], [ 0, %98 ]
ret i32 %112
}