#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 log10(double);
scalar_t__ run(char **);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int set_vol(int volume) {
  double log_vol;
  if (volume > 0) {
    log_vol = (60 * log10((double)volume)) + 22;
  } else {
    log_vol = 0;
  }
  char num[5];
  snprintf(num, 5, "%d%%", (int)log_vol);
  char *mixer[] = {"/usr/bin/amixer", "-q", "sset", "Master", num, 0};
  return run(mixer) > 0 ? 0 : 1;
}


x86 assembly (clang, -O0):
<set_vol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1163 <set_vol+0x33>
cvtsi2sdl -0x4(%rbp),%xmm0
call   1050 <log10@plt>
imul   $0x3c,%eax,%eax
add    $0x16,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    116b <set_vol+0x3b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    -0x15(%rbp),%rdi
cvttsd2si -0x10(%rbp),%ecx
mov    $0x5,%esi
lea    0xe80(%rip),%rdx
call   1040 <snprintf@plt>
lea    0xe79(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe76(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x15(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <run@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovg  %ecx,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_vol>:
push   %rbx
sub    $0x40,%rsp
test   %edi,%edi
jle    114a <set_vol+0x1a>
cvtsi2sd %edi,%xmm0
call   1050 <log10@plt>
imul   $0x3c,%eax,%ecx
add    $0x16,%ecx
jmp    114c <set_vol+0x1c>
xor    %ecx,%ecx
lea    0xead(%rip),%rdx
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <snprintf@plt>
lea    0xe99(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe9d(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe94(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe8d(%rip),%rax
mov    %rax,0x28(%rsp)
mov    %rbx,0x30(%rsp)
movq   $0x0,0x38(%rsp)
lea    0x10(%rsp),%rdi
call   1030 <run@plt>
xor    %ecx,%ecx
test   %rax,%rax
setle  %cl
mov    %ecx,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%%\00"
@.str.1 = [16 x i8] c"/usr/bin/amixer\00"
@.str.2 = [3 x i8] c"-q\00"
@.str.3 = [5 x i8] c"sset\00"
@.str.4 = [7 x i8] c"Master\00"
define i32 @set_vol(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca [5 x i8]
%5 = alloca [6 x i8*]
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* %2
%10 = sitofp i32 %9 to double
%11 = call i32 @log10(double %10)
%12 = mul nsw i32 60, %11
%13 = add nsw i32 %12, 22
%14 = sitofp i32 %13 to double
store double %14, double* %3
br label %16
15: ; preds = %1
store double 0.000000e+00, double* %3
br label %16
16: ; preds = %15, %8
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%18 = load double, double* %3
%19 = fptosi double %18 to i32
%20 = call i32 @snprintf(i8* %17, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds i8*, i8** %22, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
store i8* %26, i8** %25
%27 = getelementptr inbounds i8*, i8** %25, i64 1
store i8* null, i8** %27
%28 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 0
%29 = call i64 @run(i8** %28)
%30 = icmp sgt i64 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 0, i32 1
ret i32 %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%%\00"
@.str.1 = [16 x i8] c"/usr/bin/amixer\00"
@.str.2 = [3 x i8] c"-q\00"
@.str.3 = [5 x i8] c"sset\00"
@.str.4 = [7 x i8] c"Master\00"
define i32 @set_vol(i32 %0) {
%2 = alloca [5 x i8]
%3 = alloca [6 x i8*]
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = sitofp i32 %0 to double
%7 = tail call i32 @log10(double %6)
%8 = mul nsw i32 %7, 60
%9 = add nsw i32 %8, 22
br label %10
10: ; preds = %1, %5
%11 = phi i32 [ %9, %5 ], [ 0, %1 ]
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%13 = call i32 @snprintf(i8* %12, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%14 = bitcast [6 x i8*]* %3 to i8*
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
store i8* %12, i8** %19
%20 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 5
store i8* null, i8** %20
%21 = call i64 @run(i8** %15)
%22 = icmp slt i64 %21, 1
%23 = zext i1 %22 to i32
ret i32 %23
}