#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 int_to_percent(struct snd_ctl_elem_info *ei, int value) {
  int range = (ei->value.integer.max - ei->value.integer.min);
  if (range == 0)
    return 0;
  return ((value - ei->value.integer.min) / range) * 100;
}


x86 assembly (clang, -O0):
<int_to_percent>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
sub    0x4(%rcx),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1131 <int_to_percent+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1145 <int_to_percent+0x45>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    0x4(%rcx),%eax
cltd
idivl  -0x18(%rbp)
imul   $0x64,%eax,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_percent>:
mov    (%rdi),%ecx
mov    0x4(%rdi),%eax
sub    %eax,%ecx
je     1114 <int_to_percent+0x14>
sub    %eax,%esi
mov    %esi,%eax
cltd
idiv   %ecx
imul   $0x64,%eax,%eax
ret
xor    %eax,%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 @int_to_percent(%struct.snd_ctl_elem_info* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.snd_ctl_elem_info*
%5 = alloca i32
%6 = alloca i32
store %struct.snd_ctl_elem_info* %0, %struct.snd_ctl_elem_info** %4
store i32 %1, i32* %5
%7 = load %struct.snd_ctl_elem_info*, %struct.snd_ctl_elem_info** %4
%8 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %7, i32 0, i32 0
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %8, i32 0, i32 0
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load %struct.snd_ctl_elem_info*, %struct.snd_ctl_elem_info** %4
%13 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %12, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = sub nsw i32 %11, %16
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 0, i32* %3
br label %32
21: ; preds = %2
%22 = load i32, i32* %5
%23 = load %struct.snd_ctl_elem_info*, %struct.snd_ctl_elem_info** %4
%24 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %23, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = sub nsw i32 %22, %27
%29 = load i32, i32* %6
%30 = sdiv i32 %28, %29
%31 = mul nsw i32 %30, 100
store i32 %31, i32* %3
br label %32
32: ; preds = %21, %20
%33 = load i32, i32* %3
ret i32 %33
}

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 @int_to_percent(%struct.snd_ctl_elem_info* nocapture %0, i32 %1) {
%3 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %0, i64 0, i32 0, i32 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.snd_ctl_elem_info, %struct.snd_ctl_elem_info* %0, i64 0, i32 0, i32 0, i32 1
%6 = load i32, i32* %5
%7 = sub nsw i32 %4, %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = sub nsw i32 %1, %6
%11 = sdiv i32 %10, %7
%12 = mul nsw i32 %11, 100
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ %12, %9 ], [ 0, %2 ]
ret i32 %14
}