#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 errno;
int ioctl(int, int, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  int fd_mixer = -1;
  int balance = 0;
  int tmp = 0;
  int res;
  int delay;
  printf("opening audio mixer\n");
  fd_mixer = open("/dev/sound/mixer", O_RDWR);
  if (fd_mixer < 0) {
    printf("Error opening /dev/sound/mixer");
    return 1;
  }
  delay = 1;
  while (tmp <= 240) {
    printf("Applying balance = %d\n", balance);
    res = ioctl(fd_mixer,
                ((int)((0x40000000 | 0x20000000) |
                       ((sizeof(int) & 0x1fff) << 16) | ('Z' << 8) | 9)),
                &balance);
    if (res == -1) {
      printf("SNDCTL_MC13783_WRITE_OUT_BALANCE ioctl error: %d\n", errno);
      return -1;
    }
    balance = (balance == 100) ? 0 : (balance + 5);
    printf("Sleeping for %d seconds\n", delay);
    sleep(delay);
    tmp += delay;
  }
  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,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b5 <main+0x75>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126c <main+0x12c>
movl   $0x1,-0x24(%rbp)
cmpl   $0xf0,-0x1c(%rbp)
jg     1265 <main+0x125>
mov    -0x18(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x60045a09,%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    121b <main+0xdb>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126c <main+0x12c>
cmpl   $0x64,-0x18(%rbp)
jne    122f <main+0xef>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    1238 <main+0xf8>
mov    -0x18(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
call   1060 <sleep@plt>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11bc <main+0x7c>
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
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1240 <main+0xf0>
mov    %eax,%r13d
lea    0xe89(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rdx
mov    %r13d,%edi
mov    $0x60045a09,%esi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0xd2>
mov    $0xf1,%ebx
lea    0xea6(%rip),%r14
lea    0xe56(%rip),%r15
xor    %ebp,%ebp
lea    0x4(%rsp),%r12
mov    0x4(%rsp),%eax
lea    0x5(%rax),%ecx
cmp    $0x64,%eax
cmove  %ebp,%ecx
mov    %ecx,0x4(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
add    $0xffffffff,%ebx
je     1253 <main+0x103>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%edi
mov    $0x60045a09,%esi
mov    %r12,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x80>
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
jmp    1253 <main+0x103>
lea    0xdb9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"opening audio mixer\0A\00"
@.str.1 = [17 x i8] c"/dev/sound/mixer\00"
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"Error opening /dev/sound/mixer\00"
@.str.3 = [23 x i8] c"Applying balance = %d\0A\00"
@.str.4 = [50 x i8] c"SNDCTL_MC13783_WRITE_OUT_BALANCE ioctl error: %d\0A\00"
@errno = global i32 0
@.str.5 = [25 x i8] c"Sleeping for %d seconds\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 -1, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %49
18: ; preds = %2
store i32 1, i32* %10
br label %19
19: ; preds = %39, %18
%20 = load i32, i32* %8
%21 = icmp sle i32 %20, 240
br i1 %21, label %22, label %48
22: ; preds = %19
%23 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = call i32 @ioctl(i32 %25, i32 1610897929, i32* %7)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* @errno
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %30)
store i32 -1, i32* %3
br label %49
32: ; preds = %22
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 100
br i1 %34, label %35, label %36
35: ; preds = %32
br label %39
36: ; preds = %32
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 5
br label %39
39: ; preds = %36, %35
%40 = phi i32 [ 0, %35 ], [ %38, %36 ]
store i32 %40, i32* %7
%41 = load i32, i32* %10
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %10
%44 = call i32 @sleep(i32 %43)
%45 = load i32, i32* %10
%46 = load i32, i32* %8
%47 = add nsw i32 %46, %45
store i32 %47, i32* %8
br label %19
48: ; preds = %19
store i32 0, i32* %3
br label %49
49: ; preds = %48, %29, %16
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"/dev/sound/mixer\00"
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"Error opening /dev/sound/mixer\00"
@.str.3 = [23 x i8] c"Applying balance = %d\0A\00"
@.str.4 = [50 x i8] c"SNDCTL_MC13783_WRITE_OUT_BALANCE ioctl error: %d\0A\00"
@errno = global i32 0
@.str.5 = [25 x i8] c"Sleeping for %d seconds\0A\00"
@str = [20 x i8] c"opening audio mixer\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 0)
%11 = call i32 @ioctl(i32 %7, i32 1610897929, i32* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %15, label %18
13: ; preds = %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %33
15: ; preds = %28, %9
%16 = load i32, i32* @errno
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %33
18: ; preds = %9, %28
%19 = phi i32 [ %26, %28 ], [ 0, %9 ]
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 100
%22 = add nsw i32 %20, 5
%23 = select i1 %21, i32 0, i32 %22
store i32 %23, i32* %3
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 1)
%25 = call i32 @sleep(i32 1)
%26 = add nuw nsw i32 %19, 1
%27 = icmp eq i32 %26, 241
br i1 %27, label %33, label %28
28: ; preds = %18
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = call i32 @ioctl(i32 %7, i32 1610897929, i32* %3)
%32 = icmp eq i32 %31, -1
br i1 %32, label %15, label %18
33: ; preds = %18, %15, %13
%34 = phi i32 [ 1, %13 ], [ -1, %15 ], [ 0, %18 ]
ret i32 %34
}