#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ printf(char *, int, int);
void _print_mem_usage() {
  int tot[1];
  int res[1];
  FILE *fp = fopen("/proc/self/statm", "r");
  fscanf(fp, "%d %d", tot, res);
  printf("%.2f MB (tot), %.2f MB (res)\n", tot[0] / 1024.0, res[0] / 1024.0);
  fclose(fp);
}


x86 assembly (clang, -O0):
<_print_mem_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb9(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x4(%rbp),%rdx
lea    -0x8(%rbp),%rcx
lea    0xea9(%rip),%rsi
call   1050 <fscanf@plt>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe7c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_print_mem_usage>:
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xeb9(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cvtsi2sdl 0xc(%rsp),%xmm0
movsd  0xe7e(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
xorps  %xmm0,%xmm0
cvtsi2sdl 0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [30 x i8] c"%.2f MB (tot), %.2f MB (res)\0A\00"
define void @_print_mem_usage() {
%1 = alloca [1 x i32]
%2 = alloca [1 x i32]
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%7 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%8 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7)
%9 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%10 = load i32, i32* %9
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, 1.024000e+03
%13 = fptosi double %12 to i32
%14 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %14
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 1.024000e+03
%18 = fptosi double %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [30 x i8] c"%.2f MB (tot), %.2f MB (res)\0A\00"
define void @_print_mem_usage() {
%1 = alloca [1 x i32]
%2 = alloca [1 x i32]
%3 = bitcast [1 x i32]* %1 to i8*
%4 = bitcast [1 x i32]* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%7 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%8 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7)
%9 = load i32, i32* %6
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 0x3F50000000000000
%12 = fptosi double %11 to i32
%13 = load i32, i32* %7
%14 = sitofp i32 %13 to double
%15 = fmul double %14, 0x3F50000000000000
%16 = fptosi double %15 to i32
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %16)
%18 = call i32 @fclose(i32* %5)
ret void
}