#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*/ usage;
struct rusage {
  char *ru_maxrss;
  char *ru_ixrss;
  char *ru_idrss;
  char *ru_isrss;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ errno;
scalar_t__ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ memset(struct rusage *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
void printMemory() {
  struct rusage usage;
  memset(&usage, 0, sizeof(usage));
  if (getrusage(RUSAGE_SELF, &usage) < 0) {
    printf("Failed to get memory usage: %s\n", strerror(errno));
    return;
  }
  printf("Max Resident Set Size:   %li\n", usage.ru_maxrss);
  printf("Shared Text Memory Size: %li\n", usage.ru_ixrss);
  printf("Unshared Data Size:      %li\n", usage.ru_idrss);
  printf("Unshared Stack Size:     %li\n", usage.ru_isrss);
}


x86 assembly (clang, -O0):
<printMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1050 <getrusage@plt>
cmp    $0x0,%rax
jge    1196 <printMemory+0x56>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    11d6 <printMemory+0x96>
mov    -0x20(%rbp),%rsi
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printMemory>:
push   %rbx
sub    $0x20,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1050 <getrusage@plt>
test   %rax,%rax
js     11ad <printMemory+0x6d>
mov    (%rsp),%rsi
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%rsi
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
mov    0x18(%rsp),%rsi
lea    0xecf(%rip),%rdi
jmp    11c5 <printMemory+0x85>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe3e(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rusage = type { i8*, i8*, i8*, i8* }
@RUSAGE_SELF = global i32 0
@.str = [32 x i8] c"Failed to get memory usage: %s\0A\00"
@errno = global i32 0
@.str.1 = [30 x i8] c"Max Resident Set Size: %li\0A\00"
@.str.2 = [30 x i8] c"Shared Text Memory Size: %li\0A\00"
@.str.3 = [30 x i8] c"Unshared Data Size: %li\0A\00"
@.str.4 = [30 x i8] c"Unshared Stack Size: %li\0A\00"
define void @printMemory() {
%1 = alloca %struct.rusage
%2 = call i32 @memset(%struct.rusage* %1, i32 0, i32 32)
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i64 @getrusage(i32 %3, %struct.rusage* %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %23
10: ; preds = %0
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 1
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 2
%18 = load i8*, i8** %17
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 3
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %10, %6
ret void
}

LLVM IR (-O2):
%struct.rusage = type { i8*, i8*, i8*, i8* }
@RUSAGE_SELF = global i32 0
@.str = [32 x i8] c"Failed to get memory usage: %s\0A\00"
@errno = global i32 0
@.str.1 = [30 x i8] c"Max Resident Set Size: %li\0A\00"
@.str.2 = [30 x i8] c"Shared Text Memory Size: %li\0A\00"
@.str.3 = [30 x i8] c"Unshared Data Size: %li\0A\00"
@.str.4 = [30 x i8] c"Unshared Stack Size: %li\0A\00"
define void @printMemory() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = call i32 @memset(%struct.rusage* %1, i32 0, i32 32)
%4 = load i32, i32* @RUSAGE_SELF
%5 = call i64 @getrusage(i32 %4, %struct.rusage* %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %24
11: ; preds = %0
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 2
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 3
%22 = load i8*, i8** %21
%23 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %11, %7
ret void
}