#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 */
char *sbrk(int /*<<< orphan*/);
int calc_bytes_used(char **translation, char *startbrk) {
  int bytes;
  char *endbrk;
  *translation = "";
  endbrk = sbrk(0);
  bytes = (long)endbrk - (long)startbrk;
  if (bytes > 1e7) {
    bytes /= 1e6;
    *translation = "M";
  } else if (bytes > 1e4) {
    bytes /= 1e3;
    *translation = "K";
  }
  return bytes;
}


x86 assembly (clang, -O0):
<calc_bytes_used>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
lea    0xef8(%rip),%rcx
mov    %rcx,(%rax)
xor    %edi,%edi
call   1030 <sbrk@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xeac(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1189 <calc_bytes_used+0x79>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
lea    0xe9f(%rip),%rcx
mov    %rcx,(%rax)
jmp    11cb <calc_bytes_used+0xbb>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c6 <calc_bytes_used+0xb6>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe63(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
lea    0xe5f(%rip),%rcx
mov    %rcx,(%rax)
jmp    11cb <calc_bytes_used+0xbb>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_bytes_used>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xef2(%rip),%rax
mov    %rax,(%rdi)
xor    %edi,%edi
call   1030 <sbrk@plt>
sub    %ebx,%eax
cmp    $0x989680,%eax
jle    1145 <calc_bytes_used+0x35>
lea    0xed5(%rip),%rcx
movsd  0xebd(%rip),%xmm0
jmp    115b <calc_bytes_used+0x4b>
cmp    $0x2711,%eax
jl     116a <calc_bytes_used+0x5a>
lea    0xebf(%rip),%rcx
movsd  0xead(%rip),%xmm0
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
mov    %rcx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"M\00"
@.str.2 = [2 x i8] c"K\00"
define i32 @calc_bytes_used(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%7 = load i8**, i8*** %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = call i8* @sbrk(i32 0)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = ptrtoint i8* %9 to i64
%11 = load i8*, i8** %4
%12 = ptrtoint i8* %11 to i64
%13 = sub nsw i64 %10, %12
%14 = trunc i64 %13 to i32
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = sitofp i32 %15 to double
%17 = fcmp ogt double %16, 1.000000e+07
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* %5
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, 1.000000e+06
%22 = fptosi double %21 to i32
store i32 %22, i32* %5
%23 = load i8**, i8*** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %23
br label %35
24: ; preds = %2
%25 = load i32, i32* %5
%26 = sitofp i32 %25 to double
%27 = fcmp ogt double %26, 1.000000e+04
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i32, i32* %5
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 1.000000e+03
%32 = fptosi double %31 to i32
store i32 %32, i32* %5
%33 = load i8**, i8*** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %33
br label %34
34: ; preds = %28, %24
br label %35
35: ; preds = %34, %18
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"M\00"
@.str.2 = [2 x i8] c"K\00"
define i32 @calc_bytes_used(i8** nocapture writeonly %0, i8* %1) {
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %0
%3 = tail call i8* @sbrk(i32 0)
%4 = ptrtoint i8* %3 to i64
%5 = ptrtoint i8* %1 to i64
%6 = sub nsw i64 %4, %5
%7 = trunc i64 %6 to i32
%8 = sitofp i32 %7 to double
%9 = icmp sgt i32 %7, 10000000
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = icmp sgt i32 %7, 10000
br i1 %11, label %12, label %17
12: ; preds = %10, %2
%13 = phi double [ 1.000000e+06, %2 ], [ 1.000000e+03, %10 ]
%14 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %10 ]
%15 = fdiv double %8, %13
%16 = fptosi double %15 to i32
store i8* %14, i8** %0
br label %17
17: ; preds = %12, %10
%18 = phi i32 [ %7, %10 ], [ %16, %12 ]
ret i32 %18
}