#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 left, right;
  int vol = 0;
  int tmp = 0;
  int res = 0;
  int down = 0;
  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;
  vol = (1 << 0);
  res = ioctl(fd_mixer,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xfa)),
              &vol);
  if (res == -1) {
    printf("SOUND_MIXER_WRITE_OUTSRC ioctl error: %d\n", errno);
    return -1;
  }
  vol = 0;
  res = ioctl(
      fd_mixer,
      ((int)(0x20000000 | ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0)),
      &vol);
  if (res == -1) {
    printf("SOUND_MIXER_READ_VOLUME ioctl error: %d\n", errno);
    return -1;
  }
  left = (vol & 0x00ff);
  right = ((vol & 0xff00) >> 8);
  printf("Current output device volume = %d, %d\n", left, right);
  while (tmp <= 240) {
    printf("Applying volume = %d, %d\n", left, right);
    vol = ((left << 8) | right);
    res = ioctl(fd_mixer,
                ((int)((0x40000000 | 0x20000000) |
                       ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0)),
                &vol);
    if (res == -1) {
      printf("SOUND_MIXER_WRITE_VOLUME ioctl error: %d\n", errno);
      return -1;
    }
    if (right == 100) {
      down = 1;
    }
    if (right == 0) {
      down = 0;
    }
    if (down == 1) {
      left -= 5;
      right -= 5;
    } else {
      left += 5;
      right += 5;
    }
    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,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c3 <main+0x83>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1367 <main+0x227>
movl   $0x1,-0x30(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x60044dfa,%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1212 <main+0xd2>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1367 <main+0x227>
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x20044d00,%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    125a <main+0x11a>
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1367 <main+0x227>
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xf0,-0x24(%rbp)
jg     1360 <main+0x220>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
shl    $0x8,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x60044d00,%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    12f5 <main+0x1b5>
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1367 <main+0x227>
cmpl   $0x64,-0x1c(%rbp)
jne    1306 <main+0x1c6>
movl   $0x1,-0x2c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1317 <main+0x1d7>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    1338 <main+0x1f8>
mov    -0x18(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x1c(%rbp)
jmp    134a <main+0x20a>
mov    -0x18(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%edi
call   1060 <sleep@plt>
mov    -0x30(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1287 <main+0x147>
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
lea    0xf7b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1272 <main+0x122>
mov    %eax,%r14d
movl   $0x1,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %eax,%edi
mov    $0x60044dfa,%esi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1287 <main+0x137>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
mov    $0x20044d00,%esi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1299 <main+0x149>
mov    0x4(%rsp),%eax
movzbl %al,%ebp
movzbl %ah,%ebx
lea    0xe95(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xf1,%r13d
lea    0x4(%rsp),%r12
xor    %r15d,%r15d
jmp    1218 <main+0xc8>
nopl   0x0(%rax,%rax,1)
add    %eax,%ebp
add    %eax,%ebx
mov    $0x1,%edi
call   1070 <sleep@plt>
add    $0xffffffff,%r13d
je     12d6 <main+0x186>
lea    0xe7a(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
shl    $0x8,%eax
or     %ebx,%eax
mov    %eax,0x4(%rsp)
mov    %r14d,%edi
mov    $0x60044d00,%esi
mov    %r12,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x15b>
mov    $0x1,%eax
cmp    $0x64,%ebx
je     1257 <main+0x107>
mov    %r15d,%eax
test   %ebx,%ebx
mov    %eax,%r15d
cmove  %ebx,%r15d
mov    $0xfffffffb,%eax
cmp    $0x1,%r15d
je     1200 <main+0xb0>
mov    $0x5,%eax
jmp    1200 <main+0xb0>
lea    0xd87(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    12c7 <main+0x177>
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
jmp    12bb <main+0x16b>
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
lea    0xda0(%rip),%rdi
jmp    12bb <main+0x16b>
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    12c7 <main+0x177>

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 = [42 x i8] c"SOUND_MIXER_WRITE_OUTSRC ioctl error: %d\0A\00"
@errno = global i32 0
@.str.4 = [41 x i8] c"SOUND_MIXER_READ_VOLUME ioctl error: %d\0A\00"
@.str.5 = [39 x i8] c"Current output device volume = %d, %d\0A\00"
@.str.6 = [26 x i8] c"Applying volume = %d, %d\0A\00"
@.str.7 = [42 x i8] c"SOUND_MIXER_WRITE_VOLUME ioctl error: %d\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = 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 %92
21: ; preds = %2
store i32 1, i32* %13
store i32 1, i32* %9
%22 = load i32, i32* %6
%23 = call i32 @ioctl(i32 %22, i32 1610894842, i32* %9)
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %27)
store i32 -1, i32* %3
br label %92
29: ; preds = %21
store i32 0, i32* %9
%30 = load i32, i32* %6
%31 = call i32 @ioctl(i32 %30, i32 537152768, i32* %9)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @errno
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %35)
store i32 -1, i32* %3
br label %92
37: ; preds = %29
%38 = load i32, i32* %9
%39 = and i32 %38, 255
store i32 %39, i32* %7
%40 = load i32, i32* %9
%41 = and i32 %40, 65280
%42 = ashr i32 %41, 8
store i32 %42, i32* %8
%43 = load i32, i32* %7
%44 = load i32, i32* %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %43, i32 %44)
br label %46
46: ; preds = %85, %37
%47 = load i32, i32* %10
%48 = icmp sle i32 %47, 240
br i1 %48, label %49, label %91
49: ; preds = %46
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 %51)
%53 = load i32, i32* %7
%54 = shl i32 %53, 8
%55 = load i32, i32* %8
%56 = or i32 %54, %55
store i32 %56, i32* %9
%57 = load i32, i32* %6
%58 = call i32 @ioctl(i32 %57, i32 1610894592, i32* %9)
store i32 %58, i32* %11
%59 = load i32, i32* %11
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %49
%62 = load i32, i32* @errno
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %62)
store i32 -1, i32* %3
br label %92
64: ; preds = %49
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, 100
br i1 %66, label %67, label %68
67: ; preds = %64
store i32 1, i32* %12
br label %68
68: ; preds = %67, %64
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %68
store i32 0, i32* %12
br label %72
72: ; preds = %71, %68
%73 = load i32, i32* %12
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %80
75: ; preds = %72
%76 = load i32, i32* %7
%77 = sub nsw i32 %76, 5
store i32 %77, i32* %7
%78 = load i32, i32* %8
%79 = sub nsw i32 %78, 5
store i32 %79, i32* %8
br label %85
80: ; preds = %72
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 5
store i32 %82, i32* %7
%83 = load i32, i32* %8
%84 = add nsw i32 %83, 5
store i32 %84, i32* %8
br label %85
85: ; preds = %80, %75
%86 = load i32, i32* %13
%87 = call i32 @sleep(i32 %86)
%88 = load i32, i32* %13
%89 = load i32, i32* %10
%90 = add nsw i32 %89, %88
store i32 %90, i32* %10
br label %46
91: ; preds = %46
store i32 0, i32* %3
br label %92
92: ; preds = %91, %61, %34, %26, %19
%93 = load i32, i32* %3
ret i32 %93
}

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 = [42 x i8] c"SOUND_MIXER_WRITE_OUTSRC ioctl error: %d\0A\00"
@errno = global i32 0
@.str.4 = [41 x i8] c"SOUND_MIXER_READ_VOLUME ioctl error: %d\0A\00"
@.str.5 = [39 x i8] c"Current output device volume = %d, %d\0A\00"
@.str.6 = [26 x i8] c"Applying volume = %d, %d\0A\00"
@.str.7 = [42 x i8] c"SOUND_MIXER_WRITE_VOLUME ioctl error: %d\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*
%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 %9, label %11
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %54
11: ; preds = %2
store i32 1, i32* %3
%12 = call i32 @ioctl(i32 %7, i32 1610894842, i32* %3)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @errno
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %54
17: ; preds = %11
store i32 0, i32* %3
%18 = call i32 @ioctl(i32 %7, i32 537152768, i32* %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @errno
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %54
23: ; preds = %17
%24 = load i32, i32* %3
%25 = and i32 %24, 255
%26 = lshr i32 %24, 8
%27 = and i32 %26, 255
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %25, i32 %27)
br label %29
29: ; preds = %23, %42
%30 = phi i32 [ 0, %23 ], [ %46, %42 ]
%31 = phi i32 [ 0, %23 ], [ %52, %42 ]
%32 = phi i32 [ %27, %23 ], [ %50, %42 ]
%33 = phi i32 [ %25, %23 ], [ %49, %42 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %33, i32 %32)
%35 = shl i32 %33, 8
%36 = or i32 %35, %32
store i32 %36, i32* %3
%37 = call i32 @ioctl(i32 %7, i32 1610894592, i32* %3)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %29
%40 = load i32, i32* @errno
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %40)
br label %54
42: ; preds = %29
%43 = icmp eq i32 %32, 100
%44 = select i1 %43, i32 1, i32 %30
%45 = icmp eq i32 %32, 0
%46 = select i1 %45, i32 0, i32 %44
%47 = icmp eq i32 %46, 1
%48 = select i1 %47, i32 -5, i32 5
%49 = add nsw i32 %48, %33
%50 = add nsw i32 %48, %32
%51 = call i32 @sleep(i32 1)
%52 = add nuw nsw i32 %31, 1
%53 = icmp eq i32 %52, 241
br i1 %53, label %54, label %29
54: ; preds = %42, %39, %20, %14, %9
%55 = phi i32 [ 1, %9 ], [ -1, %14 ], [ -1, %20 ], [ -1, %39 ], [ 0, %42 ]
ret i32 %55
}