#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 KBtoMB(int /*<<< orphan*/);
int /*<<< orphan*/ abs(int);
int hexadecimal_to_decimal(char *);
int /*<<< orphan*/ printf(char *, int, int);
char *strtok(char *, char *);
int getHeapMemory(char *s) {
  char *pch;
  int highMemmory = -1, lowmemory = -1;
  pch = strtok(s, " ");
  if (pch != NULL) {
    pch = strtok(pch, "-");
    if (pch != NULL) {
      lowmemory = hexadecimal_to_decimal(pch);
      pch = strtok(NULL, "-");
      if (pch != NULL) {
        highMemmory = hexadecimal_to_decimal(pch);
      }
    }
  }
  if (lowmemory > -1 && highMemmory > -1) {
    printf("\nlowmemory = %d, highMemmory = %d\n", lowmemory, highMemmory);
    return KBtoMB(abs((highMemmory / 4096) - lowmemory));
  }
  return -1;
}


x86 assembly (clang, -O0):
<getHeapMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e9 <getHeapMemory+0x99>
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e4 <getHeapMemory+0x94>
mov    -0x18(%rbp),%rdi
call   1050 <hexadecimal_to_decimal@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe43(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11df <getHeapMemory+0x8f>
mov    -0x18(%rbp),%rdi
call   1050 <hexadecimal_to_decimal@plt>
mov    %eax,-0x1c(%rbp)
jmp    11e4 <getHeapMemory+0x94>
jmp    11e9 <getHeapMemory+0x99>
cmpl   $0xffffffff,-0x20(%rbp)
jle    1233 <getHeapMemory+0xe3>
cmpl   $0xffffffff,-0x1c(%rbp)
jle    1233 <getHeapMemory+0xe3>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdfa(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x1000,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
sub    -0x20(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,%edi
call   1030 <KBtoMB@plt>
mov    %eax,-0x4(%rbp)
jmp    123a <getHeapMemory+0xea>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHeapMemory>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11be <getHeapMemory+0x7e>
lea    0xea7(%rip),%rsi
mov    %rax,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11be <getHeapMemory+0x7e>
mov    %rax,%rdi
call   1040 <hexadecimal_to_decimal@plt>
mov    %eax,%ebx
lea    0xe89(%rip),%rsi
xor    %edi,%edi
call   1060 <strtok@plt>
test   %rax,%rax
je     11be <getHeapMemory+0x7e>
mov    %rax,%rdi
call   1040 <hexadecimal_to_decimal@plt>
test   %ebx,%ebx
js     11be <getHeapMemory+0x7e>
mov    %eax,%ebp
test   %eax,%eax
js     11be <getHeapMemory+0x7e>
lea    0xe66(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <printf@plt>
shr    $0xc,%ebp
sub    %ebx,%ebp
mov    %ebp,%edi
neg    %edi
cmovs  %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <KBtoMB@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [35 x i8] c"\0Alowmemory = %d, highMemmory = %d\0A\00"
define i32 @getHeapMemory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %5
store i32 -1, i32* %6
%7 = load i8*, i8** %3
%8 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %27
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = call i32 @hexadecimal_to_decimal(i8* %17)
store i32 %18, i32* %6
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = call i32 @hexadecimal_to_decimal(i8* %23)
store i32 %24, i32* %5
br label %25
25: ; preds = %22, %16
br label %26
26: ; preds = %25, %11
br label %27
27: ; preds = %26, %1
%28 = load i32, i32* %6
%29 = icmp sgt i32 %28, -1
br i1 %29, label %30, label %43
30: ; preds = %27
%31 = load i32, i32* %5
%32 = icmp sgt i32 %31, -1
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = load i32, i32* %6
%35 = load i32, i32* %5
%36 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32, i32* %5
%38 = sdiv i32 %37, 4096
%39 = load i32, i32* %6
%40 = sub nsw i32 %38, %39
%41 = call i32 @abs(i32 %40)
%42 = call i32 @KBtoMB(i32 %41)
store i32 %42, i32* %2
br label %44
43: ; preds = %30, %27
store i32 -1, i32* %2
br label %44
44: ; preds = %43, %33
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [35 x i8] c"\0Alowmemory = %d, highMemmory = %d\0A\00"
define i32 @getHeapMemory(i8* %0) {
%2 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = tail call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = tail call i32 @hexadecimal_to_decimal(i8* %5)
%9 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %22, label %11
11: ; preds = %7
%12 = tail call i32 @hexadecimal_to_decimal(i8* %9)
%13 = icmp sgt i32 %8, -1
%14 = icmp sgt i32 %12, -1
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %12)
%18 = lshr i32 %12, 12
%19 = sub nsw i32 %18, %8
%20 = tail call i32 @llvm.abs.i32(i32 %19, i1 true)
%21 = tail call i32 @KBtoMB(i32 %20)
br label %22
22: ; preds = %7, %1, %4, %11, %16
%23 = phi i32 [ %21, %16 ], [ -1, %11 ], [ -1, %4 ], [ -1, %1 ], [ -1, %7 ]
ret i32 %23
}