#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int max;
  int min;
};
struct TYPE_4__ {
  TYPE_1__ integer;
};
struct snd_ctl_elem_info {
  TYPE_2__ value;
};

/* Variables and functions */
int percent_to_int(struct snd_ctl_elem_info *ei, int percent) {
  int range;
  if (percent > 100)
    percent = 100;
  else if (percent < 0)
    percent = 0;
  range = (ei->value.integer.max - ei->value.integer.min);
  return ei->value.integer.min + (range * percent) / 100;
}


x86 assembly (clang, -O0):
<percent_to_int>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jle    1121 <percent_to_int+0x21>
movl   $0x64,-0xc(%rbp)
jmp    1137 <percent_to_int+0x37>
cmpl   $0x0,-0xc(%rbp)
jge    1132 <percent_to_int+0x32>
movl   $0x0,-0xc(%rbp)
jmp    1137 <percent_to_int+0x37>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    0x4(%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<percent_to_int>:
xor    %eax,%eax
test   %esi,%esi
cmovns %esi,%eax
cmp    $0x64,%eax
mov    $0x64,%ecx
cmovb  %eax,%ecx
mov    (%rdi),%eax
mov    0x4(%rdi),%edx
sub    %edx,%eax
imul   %ecx,%eax
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
add    %edx,%eax
ret

LLVM IR (-O0):
%struct.snd_ctl_elem_info = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32 }
define i32 @percent_to_int(%struct.snd_ctl_elem_info* %0, i32 %1) {
%3 = alloca %struct.snd_ctl_elem_info*
%4 = alloca i32
%5 = alloca i32
store %struct.snd_ctl_elem_info* %0, %struct.snd_ctl_elem_info** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 100
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 100, i32* %4
br label %14
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 0, i32* %4
br label %13
13: ; preds = %12, %9
br label %14
14: ; preds = %13, %8
%15 = load %struct.snd_ctl_elem_info*, %struct.snd_ctl_elem_info** %3
%16 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load %struct.snd_ctl_elem_info*, %struct.snd_ctl_elem_info** %3
%21 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %20, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = sub nsw i32 %19, %24
store i32 %25, i32* %5
%26 = load %struct.snd_ctl_elem_info*, %struct.snd_ctl_elem_info** %3
%27 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %26, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = load i32, i32* %5
%32 = load i32, i32* %4
%33 = mul nsw i32 %31, %32
%34 = sdiv i32 %33, 100
%35 = add nsw i32 %30, %34
ret i32 %35
}

LLVM IR (-O2):
%struct.snd_ctl_elem_info = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32 }
define i32 @percent_to_int(%struct.snd_ctl_elem_info* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
%4 = select i1 %3, i32 %1, i32 0
%5 = icmp ult i32 %4, 100
%6 = select i1 %5, i32 %4, i32 100
%7 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %0, i64 0, i32 0, i32 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %0, i64 0, i32 0, i32 0, i32 1
%10 = load i32, i32* %9
%11 = sub nsw i32 %8, %10
%12 = mul nsw i32 %11, %6
%13 = sdiv i32 %12, 100
%14 = add nsw i32 %13, %10
ret i32 %14
}