#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 */
long double fabs(long double);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
long double modfl(long double, long double *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void inttobinfloatpart(long double int_to_bin, char *bin_str, int precision) {
  char *bin_str_saved = malloc(96);
  memset(bin_str_saved, '\0', 96);
  int c = 0;
  if (int_to_bin < 0) {
    int_to_bin = fabs(int_to_bin);
  }
  while (c < precision) {
    long double res_int;
    long double res_float;
    res_float = modfl(int_to_bin * 2.0, &res_int);
    if (res_int == 0) {
      strcat(bin_str_saved, "0");
    } else if (res_int == 1) {
      strcat(bin_str_saved, "1");
    } else {
      return;
    }
    if (res_float == 0.0) {
      break;
    }
    int_to_bin = res_float;
    c++;
  }
  sprintf(bin_str, "%s", bin_str_saved);
  free(bin_str_saved);
}


x86 assembly (clang, -O0):
<inttobinfloatpart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    $0x60,%edi
mov    %edi,-0x54(%rbp)
call   1070 <malloc@plt>
mov    -0x54(%rbp),%edx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x2c(%rbp)
fldt   -0x10(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    11cf <inttobinfloatpart+0x5f>
jmp    11bf <inttobinfloatpart+0x4f>
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1060 <fabs@plt>
fstpt  -0x10(%rbp)
jmp    11d4 <inttobinfloatpart+0x64>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1297 <inttobinfloatpart+0x127>
fldt   -0x10(%rbp)
fadd   %st,%st(0)
mov    %rsp,%rax
fstpt  (%rax)
lea    -0x40(%rbp),%rdi
call   1050 <modfl@plt>
fstpt  -0x50(%rbp)
fldt   -0x40(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1227 <inttobinfloatpart+0xb7>
jp     1227 <inttobinfloatpart+0xb7>
jmp    1212 <inttobinfloatpart+0xa2>
mov    -0x28(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1080 <strcat@plt>
jmp    1262 <inttobinfloatpart+0xf2>
fldt   -0x40(%rbp)
fld1
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1258 <inttobinfloatpart+0xe8>
jp     1258 <inttobinfloatpart+0xe8>
jmp    1243 <inttobinfloatpart+0xd3>
mov    -0x28(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1080 <strcat@plt>
jmp    125d <inttobinfloatpart+0xed>
jmp    12b4 <inttobinfloatpart+0x144>
jmp    1262 <inttobinfloatpart+0xf2>
fldt   -0x50(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1283 <inttobinfloatpart+0x113>
jp     1283 <inttobinfloatpart+0x113>
jmp    127e <inttobinfloatpart+0x10e>
jmp    1297 <inttobinfloatpart+0x127>
fldt   -0x50(%rbp)
fstpt  -0x10(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d4 <inttobinfloatpart+0x64>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd5e(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inttobinfloatpart>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
fldt   0x90(%rsp)
fstpt  0x1c(%rsp)
mov    $0x60,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x60,%edx
call   1050 <memset@plt>
fldt   0x1c(%rsp)
test   %ebp,%ebp
jle    123e <inttobinfloatpart+0xde>
fldz
fucomi %st(1),%st
fld    %st(1)
fabs
fxch   %st(2)
fcmovnbe %st(2),%st
fstp   %st(2)
lea    0x40(%rsp),%r15
lea    0xe40(%rip),%r12
lea    0xe3b(%rip),%r13
fld1
fstpt  0x34(%rsp)
fstpt  0x28(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
fadd   %st,%st(0)
fstpt  (%rsp)
mov    %r15,%rdi
call   1060 <modfl@plt>
fldt   0x40(%rsp)
fldt   0x28(%rsp)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
mov    %r12,%rsi
jne    1202 <inttobinfloatpart+0xa2>
jnp    1215 <inttobinfloatpart+0xb5>
fldt   0x34(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
mov    %r13,%rsi
fldz
jne    1261 <inttobinfloatpart+0x101>
jp     1261 <inttobinfloatpart+0x101>
fstp   %st(0)
mov    %rbx,%rdi
fstpt  0x1c(%rsp)
call   1080 <strcat@plt>
fldt   0x28(%rsp)
fldt   0x1c(%rsp)
fucomi %st(1),%st
fstp   %st(1)
jne    1233 <inttobinfloatpart+0xd3>
jnp    123a <inttobinfloatpart+0xda>
add    $0xffffffff,%ebp
jne    11e0 <inttobinfloatpart+0x80>
jmp    123e <inttobinfloatpart+0xde>
fstp   %st(0)
fldz
fstp   %st(0)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
fstp   %st(1)
fstp   %st(0)
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [3 x i8] c"%s\00"
define void @inttobinfloatpart(x86_fp80 %0, i8* %1, i32 %2) {
%4 = alloca x86_fp80
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca x86_fp80
%10 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = call i8* @malloc(i32 96)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = call i32 @memset(i8* %12, i8 signext 0, i32 96)
store i32 0, i32* %8
%14 = load x86_fp80, x86_fp80* %4
%15 = fcmp olt x86_fp80 %14, 0xK00000000000000000000
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load x86_fp80, x86_fp80* %4
%18 = call x86_fp80 @fabs(x86_fp80 %17)
store x86_fp80 %18, x86_fp80* %4
br label %19
19: ; preds = %16, %3
br label %20
20: ; preds = %45, %19
%21 = load i32, i32* %8
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = load x86_fp80, x86_fp80* %4
%26 = fmul x86_fp80 %25, 0xK40008000000000000000
%27 = call x86_fp80 @modfl(x86_fp80 %26, x86_fp80* %9)
store x86_fp80 %27, x86_fp80* %10
%28 = load x86_fp80, x86_fp80* %9
%29 = fcmp oeq x86_fp80 %28, 0xK00000000000000000000
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i8*, i8** %7
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %41
33: ; preds = %24
%34 = load x86_fp80, x86_fp80* %9
%35 = fcmp oeq x86_fp80 %34, 0xK3FFF8000000000000000
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %7
%38 = call i32 @strcat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %40
39: ; preds = %33
br label %55
40: ; preds = %36
br label %41
41: ; preds = %40, %30
%42 = load x86_fp80, x86_fp80* %10
%43 = fcmp oeq x86_fp80 %42, 0xK00000000000000000000
br i1 %43, label %44, label %45
44: ; preds = %41
br label %49
45: ; preds = %41
%46 = load x86_fp80, x86_fp80* %10
store x86_fp80 %46, x86_fp80* %4
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %20
49: ; preds = %44, %20
%50 = load i8*, i8** %5
%51 = load i8*, i8** %7
%52 = call i32 @sprintf(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
br label %55
55: ; preds = %49, %39
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"1\00"
define void @inttobinfloatpart(x86_fp80 %0, i8* %1, i32 %2) {
%4 = alloca x86_fp80
%5 = tail call dereferenceable_or_null(96) i8* @malloc(i32 96)
%6 = tail call i32 @memset(i8* %5, i8 signext 0, i32 96)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %31
8: ; preds = %3
%9 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
%10 = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %0)
%11 = select i1 %9, x86_fp80 %10, x86_fp80 %0
%12 = bitcast x86_fp80* %4 to i8*
br label %13
13: ; preds = %8, %28
%14 = phi x86_fp80 [ %11, %8 ], [ %17, %28 ]
%15 = phi i32 [ 0, %8 ], [ %29, %28 ]
%16 = fmul x86_fp80 %14, 0xK40008000000000000000
%17 = call x86_fp80 @modfl(x86_fp80 %16, x86_fp80* %4)
%18 = load x86_fp80, x86_fp80* %4
%19 = fcmp oeq x86_fp80 %18, 0xK00000000000000000000
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = fcmp oeq x86_fp80 %18, 0xK3FFF8000000000000000
br i1 %21, label %23, label %22
22: ; preds = %20
br label %34
23: ; preds = %20, %13
%24 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %13 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %20 ]
%25 = tail call i32 @strcat(i8* %5, i8* %24)
%26 = fcmp oeq x86_fp80 %17, 0xK00000000000000000000
br i1 %26, label %27, label %28
27: ; preds = %23
br label %31
28: ; preds = %23
%29 = add nuw nsw i32 %15, 1
%30 = icmp eq i32 %29, %2
br i1 %30, label %31, label %13
31: ; preds = %28, %3, %27
%32 = tail call i8* @strcpy(i8* dereferenceable(1) %1, i8* dereferenceable(1) %5)
%33 = tail call i32 @free(i8* %5)
br label %34
34: ; preds = %22, %31
ret void
}