#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 *);
int /*<<< orphan*/ inttooct(long double, 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 __inttooctfloatpart(long double value, char *buffer, int precision) {
  char *oct_str_saved = malloc(96);
  memset(oct_str_saved, '\0', 96);
  int c = 0;
  if (value < 0) {
    value = fabs(value);
  }
  while (c < (precision)) {
    char *to_oct = malloc(48);
    memset(to_oct, '\0', 48);
    long double res_int;
    long double res_float;
    res_float = modfl(value * 8.0, &res_int);
    inttooct(res_int, to_oct);
    strcat(oct_str_saved, to_oct);
    if (res_float == 0.0) {
      break;
    }
    value = res_float;
    c++;
  }
  sprintf(buffer, "%s", oct_str_saved);
  free(oct_str_saved);
}


x86 assembly (clang, -O0):
<__inttooctfloatpart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    $0x60,%edi
mov    %edi,-0x64(%rbp)
call   1080 <malloc@plt>
mov    -0x64(%rbp),%edx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x2c(%rbp)
fldt   -0x10(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    11e2 <__inttooctfloatpart+0x62>
jmp    11d2 <__inttooctfloatpart+0x52>
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1070 <fabs@plt>
fstpt  -0x10(%rbp)
jmp    11e7 <__inttooctfloatpart+0x67>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1281 <__inttooctfloatpart+0x101>
mov    $0x30,%edi
mov    %edi,-0x68(%rbp)
call   1080 <malloc@plt>
mov    -0x68(%rbp),%edx
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1050 <memset@plt>
fldt   -0x10(%rbp)
flds   0xde5(%rip)
fmulp  %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
lea    -0x50(%rbp),%rdi
call   1060 <modfl@plt>
fstpt  -0x60(%rbp)
fldt   -0x50(%rbp)
mov    -0x38(%rbp),%rdi
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <inttooct@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <strcat@plt>
fldt   -0x60(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    126d <__inttooctfloatpart+0xed>
jp     126d <__inttooctfloatpart+0xed>
jmp    1268 <__inttooctfloatpart+0xe8>
jmp    1281 <__inttooctfloatpart+0x101>
fldt   -0x60(%rbp)
fstpt  -0x10(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e7 <__inttooctfloatpart+0x67>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd74(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__inttooctfloatpart>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
fldt   0x70(%rsp)
fstpt  0x18(%rsp)
mov    $0x60,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
xor    %ebx,%ebx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x60,%edx
call   1060 <memset@plt>
fldz
fld    %st(0)
fstpt  0x24(%rsp)
fldt   0x18(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fld    %st(0)
fabs
fxch   %st(1)
fcmovnbe %st(1),%st
fstp   %st(1)
fstpt  0x18(%rsp)
test   %ebp,%ebp
cmovle %ebx,%ebp
add    $0x1,%ebp
lea    0x30(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%ebp
je     1246 <__inttooctfloatpart+0xd6>
mov    $0x30,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
fldt   0x18(%rsp)
fmuls  0xdf5(%rip)
fstpt  (%rsp)
mov    %r15,%rdi
call   1070 <modfl@plt>
fstpt  0x18(%rsp)
fldt   0x30(%rsp)
fstpt  (%rsp)
mov    %rbx,%rdi
call   1050 <inttooct@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
fldt   0x18(%rsp)
fldt   0x24(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11e0 <__inttooctfloatpart+0x70>
jp     11e0 <__inttooctfloatpart+0x70>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @__inttooctfloatpart(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 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
%8 = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %0)
%9 = select i1 %7, x86_fp80 %8, x86_fp80 %0
%10 = bitcast x86_fp80* %4 to i8*
%11 = call i32 @llvm.smax.i32(i32 %2, i32 0)
br label %12
12: ; preds = %16, %3
%13 = phi i32 [ 0, %3 ], [ %25, %16 ]
%14 = phi x86_fp80 [ %9, %3 ], [ %20, %16 ]
%15 = icmp eq i32 %13, %11
br i1 %15, label %26, label %16
16: ; preds = %12
%17 = tail call dereferenceable_or_null(48) i8* @malloc(i32 48)
%18 = tail call i32 @memset(i8* %17, i8 signext 0, i32 48)
%19 = fmul x86_fp80 %14, 0xK40028000000000000000
%20 = call x86_fp80 @modfl(x86_fp80 %19, x86_fp80* %4)
%21 = load x86_fp80, x86_fp80* %4
%22 = tail call i32 @inttooct(x86_fp80 %21, i8* %17)
%23 = tail call i32 @strcat(i8* %5, i8* %17)
%24 = fcmp oeq x86_fp80 %20, 0xK00000000000000000000
%25 = add nuw i32 %13, 1
br i1 %24, label %26, label %12
26: ; preds = %16, %12
%27 = tail call i8* @strcpy(i8* dereferenceable(1) %1, i8* dereferenceable(1) %5)
%28 = tail call i32 @free(i8* %5)
ret void
}