#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 */
struct MEMMAN {
  int dummy;
};
struct CONSOLE {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cons_putstr0(struct CONSOLE *, char *);
int memman_total(struct MEMMAN *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, int);
void cmd_mem(struct CONSOLE *cons, unsigned int memtotal) {
  struct MEMMAN *memman = (struct MEMMAN *)0x003c0000;
  char s[60];
  sprintf(s, "total   %dMB\nfree %dKB\n\n", memtotal / (1024 * 1024),
          memman_total(memman) / 1024);
  cons_putstr0(cons, s);
  return;
}


x86 assembly (clang, -O0):
<cmd_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x3c0000,%eax
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x14,%eax
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <memman_total@plt>
mov    -0x70(%rbp),%rdi
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    -0x64(%rbp),%edx
mov    %eax,%ecx
lea    0xe86(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <cons_putstr0@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_mem>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
shr    $0x14,%ebx
mov    $0x3c0000,%edi
call   1030 <memman_total@plt>
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0xa,%ecx
lea    0xea0(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <cons_putstr0@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.CONSOLE = type { i32 }
%struct.MEMMAN = type { i32 }
@.str = [25 x i8] c"total %dMB\0Afree %dKB\0A\0A\00"
define void @cmd_mem(%struct.CONSOLE* %0, i32 %1) {
%3 = alloca %struct.CONSOLE*
%4 = alloca i32
%5 = alloca %struct.MEMMAN*
%6 = alloca [60 x i8]
store %struct.CONSOLE* %0, %struct.CONSOLE** %3
store i32 %1, i32* %4
store %struct.MEMMAN* inttoptr (i64 3932160 to %struct.MEMMAN*), %struct.MEMMAN** %5
%7 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%8 = load i32, i32* %4
%9 = udiv i32 %8, 1048576
%10 = load %struct.MEMMAN*, %struct.MEMMAN** %5
%11 = call i32 @memman_total(%struct.MEMMAN* %10)
%12 = sdiv i32 %11, 1024
%13 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12)
%14 = load %struct.CONSOLE*, %struct.CONSOLE** %3
%15 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%16 = call i32 @cons_putstr0(%struct.CONSOLE* %14, i8* %15)
ret void
}

LLVM IR (-O2):
%struct.CONSOLE = type { i32 }
%struct.MEMMAN = type { i32 }
@.str = [25 x i8] c"total %dMB\0Afree %dKB\0A\0A\00"
define void @cmd_mem(%struct.CONSOLE* %0, i32 %1) {
%3 = alloca [60 x i8]
%4 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%5 = lshr i32 %1, 20
%6 = tail call i32 @memman_total(%struct.MEMMAN* inttoptr (i64 3932160 to %struct.MEMMAN*))
%7 = sdiv i32 %6, 1024
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7)
%9 = call i32 @cons_putstr0(%struct.CONSOLE* %0, i8* %4)
ret void
}