#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_RDWR;
int /*<<< orphan*/ _SIO(char, int);
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int ac, char *av[]) {
  int fd_mixer;
  int err = 0;
  printf("Hi... \n");
  if (ac != 1) {
    printf("check_ssi_sisr <noarg>, check that SISR flags are updated "
           "correctly\n");
    return 0;
  }
  if ((fd_mixer = open("/dev/sound/mixer", O_RDWR)) < 0) {
    printf("Error opening /dev/mixer");
    err++;
    goto _err_drv_open;
  }
  if (ioctl(fd_mixer, _SIO('Z', 104), 0) < 0)
    err++;
  close(fd_mixer);
  if (err)
    goto _err_drv_open;
  return 0;
  close(fd_mixer);
_err_drv_open:
  printf("Encountered %d errors\n", err);
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
je     119f <main+0x4f>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124a <main+0xfa>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe9e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11dc <main+0x8c>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1233 <main+0xe3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x5a,%edi
mov    $0x68,%esi
call   1040 <_SIO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1210 <main+0xc0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x18(%rbp)
je     1227 <main+0xd7>
jmp    1233 <main+0xe3>
movl   $0x0,-0x4(%rbp)
jmp    124a <main+0xfa>
mov    -0x18(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebx
jne    11bf <main+0x5f>
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11cf <main+0x6f>
mov    %eax,%ebp
mov    $0x5a,%edi
mov    $0x68,%esi
call   1050 <_SIO@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1070 <close@plt>
test   %r14,%r14
jns    11f5 <main+0x95>
jmp    11dd <main+0x7d>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    11f5 <main+0x95>
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe46(%rip),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Hi... \0A\00"
@.str.1 = [69 x i8] c"check_ssi_sisr <noarg>, check that SISR flags are updated correctly\0A\00"
@.str.2 = [17 x i8] c"/dev/sound/mixer\00"
@O_RDWR = global i32 0
@.str.3 = [25 x i8] c"Error opening /dev/mixer\00"
@.str.4 = [23 x i8] c"Encountered %d errors\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %40
13: ; preds = %2
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %36
21: ; preds = %13
%22 = load i32, i32* %6
%23 = call i32 @_SIO(i8 signext 90, i32 104)
%24 = call i64 @ioctl(i32 %22, i32 %23, i32 0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %29
29: ; preds = %26, %21
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
br label %36
35: ; preds = %29
store i32 0, i32* %3
br label %40
36: ; preds = %34, %17
%37 = load i32, i32* %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %7
store i32 %39, i32* %3
br label %40
40: ; preds = %36, %35, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str.2 = [17 x i8] c"/dev/sound/mixer\00"
@O_RDWR = global i32 0
@.str.3 = [25 x i8] c"Error opening /dev/mixer\00"
@.str.4 = [23 x i8] c"Encountered %d errors\0A\00"
@str = [7 x i8] c"Hi... \00"
@str.5 = [68 x i8] c"check_ssi_sisr <noarg>, check that SISR flags are updated correctly\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %0, 1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.5, i64 0, i64 0))
br label %20
7: ; preds = %2
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %18
13: ; preds = %7
%14 = tail call i32 @_SIO(i8 signext 90, i32 104)
%15 = tail call i64 @ioctl(i32 %9, i32 %14, i32 0)
%16 = icmp slt i64 %15, 0
%17 = tail call i32 @close(i32 %9)
br i1 %16, label %18, label %20
18: ; preds = %13, %11
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %20
20: ; preds = %13, %18, %5
%21 = phi i32 [ 0, %5 ], [ 1, %18 ], [ 0, %13 ]
ret i32 %21
}