#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*/ sprintf(char *, char *, int);
char *pascal_to_pnpnpn(char *target, double P) {
  int ic;
  if (P > 10000.0) {
    ic = (int)(P * 0.01 + 0.5);
  } else {
    ic = (int)(P * 0.1 + 0.5);
  }
  sprintf(target, "%03d", ic % 1000);
  return target;
}


x86 assembly (clang, -O0):
<pascal_to_pnpnpn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1161 <pascal_to_pnpnpn+0x51>
movsd  -0x10(%rbp),%xmm0
movsd  0xed3(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xebf(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <pascal_to_pnpnpn+0x75>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe96(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
lea    0xe85(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pascal_to_pnpnpn>:
push   %rbx
xor    %eax,%eax
ucomisd 0xee5(%rip),%xmm0
seta   %al
lea    0xeeb(%rip),%rcx
mulsd  (%rcx,%rax,8),%xmm0
addsd  0xed6(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %rdi,%rbx
movslq %eax,%rdx
imul   $0x10624dd3,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%edx
lea    0xec1(%rip),%rsi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%03d\00"
define i8* @pascal_to_pnpnpn(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32
store i8* %0, i8** %3
store double %1, double* %4
%6 = load double, double* %4
%7 = fcmp ogt double %6, 1.000000e+04
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load double, double* %4
%10 = call double @llvm.fmuladd.f64(double %9, double 1.000000e-02, double 5.000000e-01)
%11 = fptosi double %10 to i32
store i32 %11, i32* %5
br label %16
12: ; preds = %2
%13 = load double, double* %4
%14 = call double @llvm.fmuladd.f64(double %13, double 1.000000e-01, double 5.000000e-01)
%15 = fptosi double %14 to i32
store i32 %15, i32* %5
br label %16
16: ; preds = %12, %8
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = srem i32 %18, 1000
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@.str = [5 x i8] c"%03d\00"
define i8* @pascal_to_pnpnpn(i8* returned writeonly %0, double %1) {
%3 = fcmp ogt double %1, 1.000000e+04
%4 = tail call double @llvm.fmuladd.f64(double %1, double 1.000000e-02, double 5.000000e-01)
%5 = tail call double @llvm.fmuladd.f64(double %1, double 1.000000e-01, double 5.000000e-01)
%6 = select i1 %3, double %4, double %5
%7 = fptosi double %6 to i32
%8 = srem i32 %7, 1000
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
ret i8* %0
}