#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 /*<<< orphan*/ getVolume(int, int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
void setVolume(int vol100, int vol255, int fd, int adr) {
  ioctl(fd, I2C_SLAVE_FORCE, adr);
  int volume = 0;
  if (vol100 != 0) {
    printf(
        "\n---------------------------------------------------------------\n");
    printf("Setting volume at 0x%02x to %d% / 124%\n", adr, vol100 - 1);
    printf("---------------------------------------------------------------\n");
    float multi = 2.06;
    volume = (int)((vol100 - 1) * multi);
  } else
    volume = vol255;
  if (volume > 255) {
    volume = 255;
  }
  char bufL[10];
  char bufR[10];
  bufL[0] = 0x3d;
  bufR[0] = 0x3e;
  if (vol100 != 0) {
    bufL[1] = ~volume;
    bufR[1] = ~volume;
  } else {
    bufL[1] = volume;
    bufR[1] = volume;
  }
  write(fd, bufL, 2);
  write(fd, bufR, 2);
  getVolume(fd, 0);
}


x86 assembly (clang, -O0):
<setVolume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1050 <ioctl@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11d4 <setVolume+0x94>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  0xe4c(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
mulss  -0x18(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <setVolume+0x9a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xff,-0x14(%rbp)
jle    11ee <setVolume+0xae>
movl   $0xff,-0x14(%rbp)
movb   $0x3d,-0x22(%rbp)
movb   $0x3e,-0x2c(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1217 <setVolume+0xd7>
mov    -0x14(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x21(%rbp)
mov    -0x14(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x2b(%rbp)
jmp    1223 <setVolume+0xe3>
mov    -0x14(%rbp),%eax
mov    %al,-0x21(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x2b(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1060 <getVolume@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setVolume>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebp
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    %edx,%edi
mov    %ecx,%edx
call   1060 <ioctl@plt>
test   %ebp,%ebp
je     11d3 <setVolume+0x83>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
add    $0xffffffff,%ebp
lea    0xe74(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
cvtsi2ss %ebp,%xmm0
mulss  0xe4d(%rip),%xmm0
cvttss2si %xmm0,%ecx
cmp    $0xff,%ecx
movb   $0x3d,0xe(%rsp)
movb   $0x3e,0x4(%rsp)
mov    $0xff,%eax
cmovl  %ecx,%eax
not    %al
jmp    11ed <setVolume+0x9d>
cmp    $0xff,%r15d
movb   $0x3d,0xe(%rsp)
movb   $0x3e,0x4(%rsp)
mov    $0xff,%eax
cmovl  %r15d,%eax
mov    %al,0xf(%rsp)
mov    %al,0x5(%rsp)
lea    0xe(%rsp),%rsi
mov    %r14d,%edi
mov    $0x2,%edx
call   1040 <write@plt>
lea    0x4(%rsp),%rsi
mov    %r14d,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %r14d,%edi
xor    %esi,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <getVolume@plt>

LLVM IR (-O0):
@I2C_SLAVE_FORCE = global i32 0
@.str = [66 x i8] c"\0A---------------------------------------------------------------\0A\00"
@.str.1 = [40 x i8] c"Setting volume at 0x%02x to %d% / 124%\0A\00"
@.str.2 = [65 x i8] c"---------------------------------------------------------------\0A\00"
define void @setVolume(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca float
%11 = alloca [10 x i8]
%12 = alloca [10 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %7
%14 = load i32, i32* @I2C_SLAVE_FORCE
%15 = load i32, i32* %8
%16 = call i32 @ioctl(i32 %13, i32 %14, i32 %15)
store i32 0, i32* %9
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %8
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
store float 0x40007AE140000000, float* %10
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = sitofp i32 %27 to float
%29 = load float, float* %10
%30 = fmul float %28, %29
%31 = fptosi float %30 to i32
store i32 %31, i32* %9
br label %34
32: ; preds = %4
%33 = load i32, i32* %6
store i32 %33, i32* %9
br label %34
34: ; preds = %32, %19
%35 = load i32, i32* %9
%36 = icmp sgt i32 %35, 255
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 255, i32* %9
br label %38
38: ; preds = %37, %34
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
store i8 61, i8* %39
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
store i8 62, i8* %40
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %38
%44 = load i32, i32* %9
%45 = xor i32 %44, -1
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 1
store i8 %46, i8* %47
%48 = load i32, i32* %9
%49 = xor i32 %48, -1
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 1
store i8 %50, i8* %51
br label %59
52: ; preds = %38
%53 = load i32, i32* %9
%54 = trunc i32 %53 to i8
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 1
store i8 %54, i8* %55
%56 = load i32, i32* %9
%57 = trunc i32 %56 to i8
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 1
store i8 %57, i8* %58
br label %59
59: ; preds = %52, %43
%60 = load i32, i32* %7
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%62 = call i32 @write(i32 %60, i8* %61, i32 2)
%63 = load i32, i32* %7
%64 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%65 = call i32 @write(i32 %63, i8* %64, i32 2)
%66 = load i32, i32* %7
%67 = call i32 @getVolume(i32 %66, i32 0)
ret void
}

LLVM IR (-O2):
@I2C_SLAVE_FORCE = global i32 0
@.str.1 = [40 x i8] c"Setting volume at 0x%02x to %d% / 124%\0A\00"
@str = [65 x i8] c"\0A---------------------------------------------------------------\00"
@str.3 = [64 x i8] c"---------------------------------------------------------------\00"
define void @setVolume(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [10 x i8]
%6 = alloca [10 x i8]
%7 = load i32, i32* @I2C_SLAVE_FORCE
%8 = tail call i32 @ioctl(i32 %2, i32 %7, i32 %3)
%9 = icmp eq i32 %0, 0
br i1 %9, label %24, label %10
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%12 = add nsw i32 %0, -1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.3, i64 0, i64 0))
%15 = sitofp i32 %12 to float
%16 = fmul float %15, 0x40007AE140000000
%17 = fptosi float %16 to i32
%18 = icmp slt i32 %17, 255
%19 = select i1 %18, i32 %17, i32 255
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
store i8 61, i8* %20
store i8 62, i8* %21
%22 = trunc i32 %19 to i8
%23 = xor i8 %22, -1
br label %30
24: ; preds = %4
%25 = icmp slt i32 %1, 255
%26 = select i1 %25, i32 %1, i32 255
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
store i8 61, i8* %27
store i8 62, i8* %28
%29 = trunc i32 %26 to i8
br label %30
30: ; preds = %24, %10
%31 = phi i8 [ %29, %24 ], [ %23, %10 ]
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 1
store i8 %31, i8* %32
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 1
store i8 %31, i8* %33
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%36 = call i32 @write(i32 %2, i8* %34, i32 2)
%37 = call i32 @write(i32 %2, i8* %35, i32 2)
%38 = tail call i32 @getVolume(i32 %2, i32 0)
ret void
}