#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 *);
scalar_t__ ioctl(int, int, int *);
int open(char *, int /*<<< orphan*/);
scalar_t__ play_file(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ set_audio_config(int, int /*<<< orphan*/ *);
int main(int ac, char *av[]) {
  FILE *fd_file;
  int fd_audio, fd_audio2;
  int err = 0, val;
  printf("Hi... \n");
  if (ac != 4) {
    printf("This program checks that it is possible to choose ");
    printf("the device on which to play (StDAC or CODEC)\n");
    printf("It plays on StDAC then CODEC and StDAC again (checks device "
           "toggling)\n");
    printf("-> main <SSI> <file4StDAC.wav> <file4CODEC.wav>\n\n");
    printf("   SSI: 1 for SSI1, 2 for SSI2\n");
    return 0;
  }
  if ((fd_audio = open("/dev/sound/dsp", O_WRONLY)) < 0) {
    printf("Error opening /dev/dsp");
    return 0;
  }
  if (atoi(av[1]) == 2) {
    fd_audio2 = fd_audio;
    if ((fd_audio = open("/dev/sound/dsp1", O_WRONLY)) < 0) {
      printf("Error opening /dev/dsp1");
      close(fd_audio2);
      return 0;
    }
  }
  val = (1 << 4);
  if (ioctl(fd_audio, ((int)(0x00000000 | ('Z' << 8) | 2)), 0) < 0)
    err++;
  if (ioctl(fd_audio,
            ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
                   ('M' << 8) | 0xfa)),
            &val) < 0)
    err++;
  if ((fd_file = fopen(av[2], "r")) <= 0) {
    goto _err_file_not_found;
  }
  if (set_audio_config(fd_audio, fd_file) < 0) {
    printf("Bad format for file 1\n");
    err++;
    goto _err_fmt;
  }
  err += play_file(fd_audio, fd_file);
  fclose(fd_file);
  val = (1 << 4);
  if (ioctl(fd_audio, ((int)(0x00000000 | ('Z' << 8) | 3)), 0) < 0)
    err++;
  if (ioctl(fd_audio,
            ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
                   ('M' << 8) | 0xfa)),
            &val) < 0)
    err++;
  if ((fd_file = fopen(av[3], "r")) <= 0) {
    goto _err_file_not_found;
  }
  if (set_audio_config(fd_audio, fd_file) < 0) {
    printf("Bad format for file 1\n");
    err++;
    goto _err_fmt;
  }
  err += play_file(fd_audio, fd_file);
  fclose(fd_file);
  if (ioctl(fd_audio, ((int)(0x00000000 | ('Z' << 8) | 2)), 0) < 0)
    err++;
  if (ioctl(fd_audio,
            ((int)((0x40000000 | 0x20000000) | ((sizeof(int) & 0x1fff) << 16) |
                   ('M' << 8) | 0xfa)),
            &val) < 0)
    err++;
  if ((fd_file = fopen(av[2], "r")) <= 0) {
    goto _err_file_not_found;
  }
  if (set_audio_config(fd_audio, fd_file) < 0) {
    printf("Bad format for file 1\n");
    err++;
    goto _err_fmt;
  }
  err += play_file(fd_audio, fd_file);
  fclose(fd_file);
  close(fd_audio);
  if (err)
    goto _end_err;
  printf("All tests passed with success\n");
  return 0;
_err_fmt:
  close(fd_audio);
_end_err:
  printf("Encountered %d errors\n", err);
  return err;
_err_file_not_found:
  printf("Error opening the file %s \n", av[2]);
  close(fd_audio);
  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   $0x0,-0x24(%rbp)
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
je     1217 <main+0x87>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1587 <main+0x3f7>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    0xedb(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1252 <main+0xc2>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1587 <main+0x3f7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
cmp    $0x2,%eax
jne    12b6 <main+0x126>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12b1 <main+0x121>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1587 <main+0x3f7>
jmp    12b6 <main+0x126>
movl   $0x10,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x5a02,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    12e1 <main+0x151>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x28(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1305 <main+0x175>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
ja     132c <main+0x19c>
jmp    1562 <main+0x3d2>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <set_audio_config@plt>
cmp    $0x0,%rax
jge    135e <main+0x1ce>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    153e <main+0x3ae>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <play_file@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x10,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x5a03,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    13ab <main+0x21b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x28(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    13cf <main+0x23f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd72(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
ja     13f6 <main+0x266>
jmp    1562 <main+0x3d2>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <set_audio_config@plt>
cmp    $0x0,%rax
jge    1428 <main+0x298>
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    153e <main+0x3ae>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <play_file@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5a02,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    146e <main+0x2de>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x28(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1492 <main+0x302>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xcaf(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
ja     14b9 <main+0x329>
jmp    1562 <main+0x3d2>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <set_audio_config@plt>
cmp    $0x0,%rax
jge    14eb <main+0x35b>
lea    0xc7c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    153e <main+0x3ae>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <play_file@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x0,-0x24(%rbp)
je     1524 <main+0x394>
jmp    1546 <main+0x3b6>
lea    0xc3e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1587 <main+0x3f7>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%esi
lea    0xc38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1587 <main+0x3f7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xc2e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x4,%ebx
jne    1223 <main+0x83>
mov    0x2e0d(%rip),%rbx
mov    (%rbx),%esi
lea    0xe5f(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1269 <main+0xc9>
mov    %eax,%ebp
mov    0x8(%r12),%rdi
call   10c0 <atoi@plt>
cmp    $0x2,%eax
jne    127f <main+0xdf>
mov    (%rbx),%esi
lea    0xe5a(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1282 <main+0xe2>
lea    0xe57(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
jmp    1446 <main+0x2a6>
lea    0xdd6(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
lea    0xf11(%rip),%rdi
call   1030 <puts@plt>
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
jmp    1479 <main+0x2d9>
lea    0xdd2(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1479 <main+0x2d9>
mov    %ebp,%r14d
movl   $0x10,0xc(%rsp)
xor    %r15d,%r15d
mov    %r14d,%edi
mov    $0x5a02,%esi
xor    %edx,%edx
call   1080 <ioctl@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    $0x60044dfa,%esi
call   1080 <ioctl@plt>
mov    %rax,%r13
mov    0x10(%r12),%rdi
lea    0xdc1(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1430 <main+0x290>
mov    %rax,%rbp
shr    $0x3f,%rbx
shr    $0x3f,%r13
add    %ebx,%r13d
mov    %r14d,%edi
mov    %rax,%rsi
call   1040 <set_audio_config@plt>
test   %rax,%rax
js     144d <main+0x2ad>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <play_file@plt>
mov    %rax,0x10(%rsp)
mov    %rbp,%rdi
call   1060 <fclose@plt>
movl   $0x10,0xc(%rsp)
mov    %r14d,%edi
mov    $0x5a03,%esi
xor    %edx,%edx
call   1080 <ioctl@plt>
mov    %rax,%rbp
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    $0x60044dfa,%esi
call   1080 <ioctl@plt>
mov    %rax,%rbx
mov    0x18(%r12),%rdi
lea    0xd3e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1430 <main+0x290>
add    0x10(%rsp),%r13d
shr    $0x3f,%rbp
add    %r13d,%ebp
shr    $0x3f,%rbx
mov    %ebx,%r13d
add    %ebp,%r13d
mov    %r14d,%edi
mov    %rax,%rbx
mov    %rax,%rsi
call   1040 <set_audio_config@plt>
test   %rax,%rax
js     144d <main+0x2ad>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <play_file@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14d,%edi
mov    $0x5a02,%esi
xor    %edx,%edx
call   1080 <ioctl@plt>
mov    %rax,%rbp
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    $0x60044dfa,%esi
call   1080 <ioctl@plt>
mov    %rax,%rbx
mov    0x10(%r12),%rdi
lea    0xcb8(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1430 <main+0x290>
add    0x10(%rsp),%r13d
shr    $0x3f,%rbp
add    %r13d,%ebp
shr    $0x3f,%rbx
mov    %ebx,%r13d
add    %ebp,%r13d
mov    %r14d,%edi
mov    %rax,%rbp
mov    %rax,%rsi
call   1040 <set_audio_config@plt>
test   %rax,%rax
js     144d <main+0x2ad>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <play_file@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %r14d,%edi
call   1090 <close@plt>
add    %ebx,%r13d
jne    1465 <main+0x2c5>
lea    0xc97(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
jmp    1479 <main+0x2d9>
mov    0x10(%r12),%rsi
lea    0xc5e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
jmp    1479 <main+0x2d9>
lea    0xc87(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r13d
mov    %r14d,%edi
call   1090 <close@plt>
lea    0xc17(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [51 x i8] c"This program checks that it is possible to choose \00"
@.str.6 = [15 x i8] c"/dev/sound/dsp\00"
@O_WRONLY = global i32 0
@.str.7 = [23 x i8] c"Error opening /dev/dsp\00"
@.str.8 = [16 x i8] c"/dev/sound/dsp1\00"
@.str.9 = [24 x i8] c"Error opening /dev/dsp1\00"
@.str.10 = [2 x i8] c"r\00"
@.str.13 = [23 x i8] c"Encountered %d errors\0A\00"
@.str.14 = [28 x i8] c"Error opening the file %s \0A\00"
@str = [7 x i8] c"Hi... \00"
@str.15 = [30 x i8] c"All tests passed with success\00"
@str.18 = [22 x i8] c"Bad format for file 1\00"
@str.19 = [45 x i8] c"the device on which to play (StDAC or CODEC)\00"
@str.20 = [70 x i8] c"It plays on StDAC then CODEC and StDAC again (checks device toggling)\00"
@str.21 = [49 x i8] c"-> main <SSI> <file4StDAC.wav> <file4CODEC.wav>\0A\00"
@str.22 = [31 x i8] c" SSI: 1 for SSI1, 2 for SSI2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i32 %0, 4
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.19, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.20, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.21, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.22, i64 0, i64 0))
br label %108
13: ; preds = %2
%14 = load i32, i32* @O_WRONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %108
19: ; preds = %13
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i32, i32* @O_WRONLY
%26 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%30 = tail call i32 @close(i32 %15)
br label %108
31: ; preds = %24, %19
%32 = phi i32 [ %26, %24 ], [ %15, %19 ]
store i32 16, i32* %3
%33 = tail call i64 @ioctl(i32 %32, i32 23042, i32* null)
%34 = lshr i64 %33, 63
%35 = trunc i64 %34 to i32
%36 = call i64 @ioctl(i32 %32, i32 1610894842, i32* %3)
%37 = lshr i64 %36, 63
%38 = trunc i64 %37 to i32
%39 = add nuw nsw i32 %38, %35
%40 = getelementptr inbounds i8*, i8** %1, i64 2
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%43 = icmp eq i32* %42, null
br i1 %43, label %104, label %44
44: ; preds = %31
%45 = call i64 @set_audio_config(i32 %32, i32* %42)
%46 = icmp slt i64 %45, 0
br i1 %46, label %95, label %47
47: ; preds = %44
%48 = call i64 @play_file(i32 %32, i32* %42)
%49 = trunc i64 %48 to i32
%50 = add i32 %39, %49
%51 = call i32 @fclose(i32* %42)
store i32 16, i32* %3
%52 = call i64 @ioctl(i32 %32, i32 23043, i32* null)
%53 = lshr i64 %52, 63
%54 = trunc i64 %53 to i32
%55 = add nsw i32 %50, %54
%56 = call i64 @ioctl(i32 %32, i32 1610894842, i32* %3)
%57 = lshr i64 %56, 63
%58 = trunc i64 %57 to i32
%59 = add nsw i32 %55, %58
%60 = getelementptr inbounds i8*, i8** %1, i64 3
%61 = load i8*, i8** %60
%62 = call i32* @fopen(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%63 = icmp eq i32* %62, null
br i1 %63, label %104, label %64
64: ; preds = %47
%65 = call i64 @set_audio_config(i32 %32, i32* %62)
%66 = icmp slt i64 %65, 0
br i1 %66, label %95, label %67
67: ; preds = %64
%68 = call i64 @play_file(i32 %32, i32* %62)
%69 = trunc i64 %68 to i32
%70 = add i32 %59, %69
%71 = call i32 @fclose(i32* %62)
%72 = call i64 @ioctl(i32 %32, i32 23042, i32* null)
%73 = lshr i64 %72, 63
%74 = trunc i64 %73 to i32
%75 = add nsw i32 %70, %74
%76 = call i64 @ioctl(i32 %32, i32 1610894842, i32* %3)
%77 = lshr i64 %76, 63
%78 = trunc i64 %77 to i32
%79 = add nsw i32 %75, %78
%80 = load i8*, i8** %40
%81 = call i32* @fopen(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%82 = icmp eq i32* %81, null
br i1 %82, label %104, label %83
83: ; preds = %67
%84 = call i64 @set_audio_config(i32 %32, i32* %81)
%85 = icmp slt i64 %84, 0
br i1 %85, label %95, label %86
86: ; preds = %83
%87 = call i64 @play_file(i32 %32, i32* %81)
%88 = trunc i64 %87 to i32
%89 = add i32 %79, %88
%90 = call i32 @fclose(i32* %81)
%91 = call i32 @close(i32 %32)
%92 = icmp eq i32 %89, 0
br i1 %92, label %93, label %101
93: ; preds = %86
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.15, i64 0, i64 0))
br label %108
95: ; preds = %83, %64, %44
%96 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.18, i64 0, i64 0), %44 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.18, i64 0, i64 0), %64 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.18, i64 0, i64 0), %83 ]
%97 = phi i32 [ %39, %44 ], [ %59, %64 ], [ %79, %83 ]
%98 = call i32 @puts(i8* dereferenceable(1) %96)
%99 = add nsw i32 %97, 1
%100 = call i32 @close(i32 %32)
br label %101
101: ; preds = %86, %95
%102 = phi i32 [ %99, %95 ], [ %89, %86 ]
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i32 %102)
br label %108
104: ; preds = %67, %47, %31
%105 = load i8*, i8** %40
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0), i8* %105)
%107 = call i32 @close(i32 %32)
br label %108
108: ; preds = %104, %101, %93, %28, %17, %7
%109 = phi i32 [ 0, %7 ], [ 0, %17 ], [ 0, %28 ], [ 0, %104 ], [ %102, %101 ], [ 0, %93 ]
ret i32 %109
}