#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*/ I2C_SLAVE_FORCE;
int getVolume(int, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setVolume(int /*<<< orphan*/, int, int, int);
void setVolumeSwitch(int type, int fd, int adr) {
  ioctl(fd, I2C_SLAVE_FORCE, adr);
  int currentVol = getVolume(fd, 1);
  if (type == 0) {
    printf(
        "\n---------------------------------------------------------------\n");
    printf("Reduced volume at 0x%02x by -0.5dB\n", adr);
    printf("---------------------------------------------------------------\n");
    setVolume(0, currentVol + 1, fd, adr);
  } else {
    printf(
        "\n---------------------------------------------------------------\n");
    printf("Raised volume at 0x%02x by 0.5dB\n", adr);
    printf("---------------------------------------------------------------\n");
    if (currentVol > 0)
      setVolume(0, currentVol - 1, fd, adr);
    else
      setVolume(0, currentVol, fd, adr);
  }
}


x86 assembly (clang, -O0):
<setVolumeSwitch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1040 <ioctl@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1060 <getVolume@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11c4 <setVolumeSwitch+0x84>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
xor    %edi,%edi
call   1050 <setVolume@plt>
jmp    1228 <setVolumeSwitch+0xe8>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jle    1213 <setVolumeSwitch+0xd3>
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
xor    %edi,%edi
call   1050 <setVolume@plt>
jmp    1223 <setVolumeSwitch+0xe3>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
xor    %edi,%edi
call   1050 <setVolume@plt>
jmp    1228 <setVolumeSwitch+0xe8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setVolumeSwitch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r12d
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1050 <ioctl@plt>
mov    $0x1,%ebp
mov    %r15d,%edi
mov    $0x1,%esi
call   1070 <getVolume@plt>
mov    %eax,%ebx
lea    0xeb9(%rip),%rdi
test   %r12d,%r12d
je     11c0 <setVolumeSwitch+0x70>
call   1030 <puts@plt>
lea    0xe86(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
test   %ebx,%ebx
setg   %bpl
neg    %ebp
jmp    11e2 <setVolumeSwitch+0x92>
call   1030 <puts@plt>
lea    0xe34(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
add    %ebp,%ebx
xor    %edi,%edi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <setVolume@plt>

LLVM IR (-O0):
@I2C_SLAVE_FORCE = global i32 0
@.str = [66 x i8] c"\0A---------------------------------------------------------------\0A\00"
@.str.1 = [36 x i8] c"Reduced volume at 0x%02x by -0.5dB\0A\00"
@.str.2 = [65 x i8] c"---------------------------------------------------------------\0A\00"
@.str.3 = [34 x i8] c"Raised volume at 0x%02x by 0.5dB\0A\00"
define void @setVolumeSwitch(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* @I2C_SLAVE_FORCE
%10 = load i32, i32* %6
%11 = call i32 @ioctl(i32 %8, i32 %9, i32 %10)
%12 = load i32, i32* %5
%13 = call i32 @getVolume(i32 %12, i32 1)
store i32 %13, i32* %7
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i32 @setVolume(i32 0, i32 %22, i32 %23, i32 %24)
br label %45
26: ; preds = %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %7
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %26
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = call i32 @setVolume(i32 0, i32 %35, i32 %36, i32 %37)
br label %44
39: ; preds = %26
%40 = load i32, i32* %7
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = call i32 @setVolume(i32 0, i32 %40, i32 %41, i32 %42)
br label %44
44: ; preds = %39, %33
br label %45
45: ; preds = %44, %16
ret void
}

LLVM IR (-O2):
@I2C_SLAVE_FORCE = global i32 0
@.str.1 = [36 x i8] c"Reduced volume at 0x%02x by -0.5dB\0A\00"
@.str.3 = [34 x i8] c"Raised volume at 0x%02x by 0.5dB\0A\00"
@str.5 = [65 x i8] c"\0A---------------------------------------------------------------\00"
@str.6 = [64 x i8] c"---------------------------------------------------------------\00"
define void @setVolumeSwitch(i32 %0, i32 %1, i32 %2) {
%4 = load i32, i32* @I2C_SLAVE_FORCE
%5 = tail call i32 @ioctl(i32 %1, i32 %4, i32 %2)
%6 = tail call i32 @getVolume(i32 %1, i32 1)
%7 = icmp eq i32 %0, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.5, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.6, i64 0, i64 0))
br label %18
12: ; preds = %3
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.5, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %2)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.6, i64 0, i64 0))
%16 = icmp sgt i32 %6, 0
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %12, %8
%19 = phi i32 [ %17, %12 ], [ 1, %8 ]
%20 = add nsw i32 %6, %19
%21 = tail call i32 @setVolume(i32 0, i32 %20, i32 %1, i32 %2)
ret void
}