#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*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
int /*<<< orphan*/ printf(char *, int, int, int);
int main() {
  FILE *f = fopen("/proc/self/statm", "r");
  int size, resident, shared;
  if (fscanf(f, "%d %d %d", &size, &resident, &shared) == 3) {
    printf("%dK total size, %dK resident, %dK shared\n", size * 4, resident * 4,
           shared * 4);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1040 <fscanf@plt>
cmp    $0x3,%eax
jne    1199 <main+0x69>
mov    -0x14(%rbp),%esi
shl    $0x2,%esi
mov    -0x18(%rbp),%edx
shl    $0x2,%edx
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xec5(%rip),%rdi
lea    0xecf(%rip),%rsi
call   1050 <fopen@plt>
lea    0xec5(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x3,%eax
jne    118b <main+0x5b>
mov    0x14(%rsp),%esi
shl    $0x2,%esi
mov    0x10(%rsp),%edx
shl    $0x2,%edx
mov    0xc(%rsp),%ecx
shl    $0x2,%ecx
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [42 x i8] c"%dK total size, %dK resident, %dK shared\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = 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* %6, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %18
10: ; preds = %0
%11 = load i32, i32* %3
%12 = mul nsw i32 %11, 4
%13 = load i32, i32* %4
%14 = mul nsw i32 %13, 4
%15 = load i32, i32* %5
%16 = mul nsw i32 %15, 4
%17 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %14, i32 %16)
br label %18
18: ; preds = %10, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [42 x i8] c"%dK total size, %dK resident, %dK shared\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = 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))
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %18
10: ; preds = %0
%11 = load i32, i32* %1
%12 = shl nsw i32 %11, 2
%13 = load i32, i32* %2
%14 = shl nsw i32 %13, 2
%15 = load i32, i32* %3
%16 = shl nsw i32 %15, 2
%17 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %14, i32 %16)
br label %18
18: ; preds = %10, %0
ret i32 0
}