#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 int /*<<< orphan*/ temp;

/* Variables and functions */
size_t dlmalloc_footprint();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long, long);
int /*<<< orphan*/ printf(char *, long, long);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  size_t initial = dlmalloc_footprint();
  size_t final;
  char temp[64];
  int n;
  for (n = 0; n < 10000; n++)
    snprintf(temp, sizeof(temp), "%g", n * 0.647287623);
  final = dlmalloc_footprint();
  if (final <= 4096) {
    printf("OK: initial = %ld, final == %ld\n", (long)initial, (long) final);
    return 0;
  } else {
    fprintf(stderr, "KO: initial == %ld, final == %ld\n", (long)initial,
            (long) final);
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <dlmalloc_footprint@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x2710,-0x64(%rbp)
jge    11a6 <main+0x66>
lea    -0x60(%rbp),%rdi
cvtsi2sdl -0x64(%rbp),%xmm0
movsd  0xe81(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    $0x40,%esi
lea    0xe75(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1161 <main+0x21>
mov    $0x0,%al
call   1060 <dlmalloc_footprint@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1000,-0x18(%rbp)
ja     11df <main+0x9f>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1203 <main+0xc3>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe35(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
xor    %eax,%eax
call   1060 <dlmalloc_footprint@plt>
mov    %rax,%r14
xorpd  %xmm0,%xmm0
mov    $0x2710,%ebp
lea    0xeac(%rip),%r15
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe7c(%rip),%xmm0
cvttsd2si %xmm0,%ecx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15,%rdx
call   1040 <snprintf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xe62(%rip),%xmm0
add    $0xffffffff,%ebp
jne    1170 <main+0x30>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <dlmalloc_footprint@plt>
cmp    $0x1000,%rax
ja     11d0 <main+0x90>
lea    0xe50(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
jmp    11f0 <main+0xb0>
mov    0x2e09(%rip),%rcx
mov    (%rcx),%edi
lea    0xe54(%rip),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%g\00"
@.str.1 = [33 x i8] c"OK: initial = %ld, final == %ld\0A\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"KO: initial == %ld, final == %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca [64 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 (...) @dlmalloc_footprint()
store i64 %6, i64* %2
store i32 0, i32* %5
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 10000
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 0x3FE4B694887C7F9C
%15 = fptosi double %14 to i32
%16 = call i32 @snprintf(i8* %11, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %10
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %7
20: ; preds = %7
%21 = call i64 (...) @dlmalloc_footprint()
store i64 %21, i64* %3
%22 = load i64, i64* %3
%23 = icmp ule i64 %22, 4096
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i64, i64* %2
%26 = load i64, i64* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %25, i64 %26)
store i32 0, i32* %1
br label %33
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i64, i64* %2
%31 = load i64, i64* %3
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %30, i64 %31)
store i32 1, i32* %1
br label %33
33: ; preds = %28, %24
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"%g\00"
@.str.1 = [33 x i8] c"OK: initial = %ld, final == %ld\0A\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"KO: initial == %ld, final == %ld\0A\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = tail call i64 (...) @dlmalloc_footprint()
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %10, %4 ]
%6 = sitofp i32 %5 to double
%7 = fmul double %6, 0x3FE4B694887C7F9C
%8 = fptosi double %7 to i32
%9 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, 10000
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = call i64 (...) @dlmalloc_footprint()
%14 = icmp ult i64 %13, 4097
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %2, i64 %13)
br label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %2, i64 %13)
br label %20
20: ; preds = %17, %15
%21 = phi i32 [ 0, %15 ], [ 1, %17 ]
ret i32 %21
}