#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 */
typedef double int64_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
void pfl_fmt_ratio(char buf[7], int64_t n, int64_t d) {
  double val;
  if (n == d)
    snprintf(buf, 7, "100%%");
  else if (n == 0)
    snprintf(buf, 7, "0%%");
  else if (d == 0)
    snprintf(buf, 7, "<und>");
  else {
    val = n * 100.0 / d;
    if (val > 99.99)
      snprintf(buf, 7, "99.99%%");
    else
      snprintf(buf, 7, "%.2f%%", val);
  }
}


x86 assembly (clang, -O0):
<pfl_fmt_ratio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1158 <pfl_fmt_ratio+0x48>
jp     1158 <pfl_fmt_ratio+0x48>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
lea    0xec4(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1235 <pfl_fmt_ratio+0x125>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118c <pfl_fmt_ratio+0x7c>
jp     118c <pfl_fmt_ratio+0x7c>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
lea    0xe92(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1230 <pfl_fmt_ratio+0x120>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c0 <pfl_fmt_ratio+0xb0>
jp     11c0 <pfl_fmt_ratio+0xb0>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
lea    0xe62(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    122b <pfl_fmt_ratio+0x11b>
movsd  0xe40(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe1c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    120a <pfl_fmt_ratio+0xfa>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
lea    0xe1e(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1226 <pfl_fmt_ratio+0x116>
mov    -0x8(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
mov    $0x7,%esi
lea    0xe05(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    122b <pfl_fmt_ratio+0x11b>
jmp    1230 <pfl_fmt_ratio+0x120>
jmp    1235 <pfl_fmt_ratio+0x125>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfl_fmt_ratio>:
ucomisd %xmm1,%xmm0
jne    1121 <pfl_fmt_ratio+0x11>
jp     1121 <pfl_fmt_ratio+0x11>
lea    0xef1(%rip),%rdx
jmp    1164 <pfl_fmt_ratio+0x54>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    1136 <pfl_fmt_ratio+0x26>
jp     1136 <pfl_fmt_ratio+0x26>
lea    0xede(%rip),%rdx
jmp    1164 <pfl_fmt_ratio+0x54>
ucomisd %xmm2,%xmm1
jne    1147 <pfl_fmt_ratio+0x37>
jp     1147 <pfl_fmt_ratio+0x37>
lea    0xed1(%rip),%rdx
jmp    1164 <pfl_fmt_ratio+0x54>
mulsd  0xeb1(%rip),%xmm0
divsd  %xmm1,%xmm0
ucomisd 0xead(%rip),%xmm0
jbe    1170 <pfl_fmt_ratio+0x60>
lea    0xeb8(%rip),%rdx
mov    $0x7,%esi
xor    %eax,%eax
jmp    1030 <snprintf@plt>
lea    0xead(%rip),%rdx
mov    $0x7,%esi
mov    $0x1,%al
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"100%%\00"
@.str.1 = [4 x i8] c"0%%\00"
@.str.2 = [6 x i8] c"<und>\00"
@.str.3 = [8 x i8] c"99.99%%\00"
@.str.4 = [7 x i8] c"%.2f%%\00"
define void @pfl_fmt_ratio(i8* %0, double %1, double %2) {
%4 = alloca i8*
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i8* %0, i8** %4
store double %1, double* %5
store double %2, double* %6
%8 = load double, double* %5
%9 = load double, double* %6
%10 = fcmp oeq double %8, %9
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %12, i32 7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %43
14: ; preds = %3
%15 = load double, double* %5
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %18, i32 7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %42
20: ; preds = %14
%21 = load double, double* %6
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %24, i32 7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %41
26: ; preds = %20
%27 = load double, double* %5
%28 = fmul double %27, 1.000000e+02
%29 = load double, double* %6
%30 = fdiv double %28, %29
store double %30, double* %7
%31 = load double, double* %7
%32 = fcmp ogt double %31, 0x4058FF5C28F5C28F
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i8*, i8** %4
%35 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %34, i32 7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %40
36: ; preds = %26
%37 = load i8*, i8** %4
%38 = load double, double* %7
%39 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %37, i32 7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %38)
br label %40
40: ; preds = %36, %33
br label %41
41: ; preds = %40, %23
br label %42
42: ; preds = %41, %17
br label %43
43: ; preds = %42, %11
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"100%%\00"
@.str.1 = [4 x i8] c"0%%\00"
@.str.2 = [6 x i8] c"<und>\00"
@.str.3 = [8 x i8] c"99.99%%\00"
@.str.4 = [7 x i8] c"%.2f%%\00"
define void @pfl_fmt_ratio(i8* %0, double %1, double %2) {
%4 = fcmp oeq double %1, %2
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %23
7: ; preds = %3
%8 = fcmp oeq double %1, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %23
11: ; preds = %7
%12 = fcmp oeq double %2, 0.000000e+00
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %23
15: ; preds = %11
%16 = fmul double %1, 1.000000e+02
%17 = fdiv double %16, %2
%18 = fcmp ogt double %17, 0x4058FF5C28F5C28F
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %23
21: ; preds = %15
%22 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %17)
br label %23
23: ; preds = %9, %19, %21, %13, %5
ret void
}