#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 timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/, unsigned long, unsigned long,
                           unsigned long, unsigned long, unsigned long,
                           unsigned long, unsigned long);
int fscanf(int /*<<< orphan*/ *, char *, unsigned long *, unsigned long *,
           unsigned long *, unsigned long *, unsigned long *, unsigned long *,
           unsigned long *);
int /*<<< orphan*/ stderr;
void log_memory_status() {
  FILE *f = fopen("/proc/self/statm", "r");
  if (!f)
    return;
  unsigned long size, resident, share, text, lib, data, dt;
  if (7 != fscanf(f, "%ld %ld %ld %ld %ld %ld %ld", &size, &resident, &share,
                  &text, &lib, &data, &dt))
    return;
  struct timespec ts;
  clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
  fprintf(stderr, "\n%ld.%09ld %ld %ld %ld %ld %ld %ld %ld", ts.tv_sec,
          ts.tv_nsec, size, resident, share, text, lib, data, dt);
  fclose(f);
}


x86 assembly (clang, -O0):
<log_memory_status>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1182 <log_memory_status+0x32>
jmp    123a <log_memory_status+0xea>
mov    -0x18(%rbp),%rdi
lea    0xe91(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x38(%rbp),%r9
lea    -0x40(%rbp),%r11
lea    -0x48(%rbp),%r10
lea    -0x50(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1050 <fscanf@plt>
mov    %eax,%ecx
mov    $0x7,%eax
cmp    %ecx,%eax
je     11d0 <log_memory_status+0x80>
jmp    123a <log_memory_status+0xea>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    -0x58(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%r14
mov    -0x38(%rbp),%rbx
mov    -0x40(%rbp),%r11
mov    -0x48(%rbp),%r10
mov    -0x50(%rbp),%rax
lea    0xdff(%rip),%rsi
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_memory_status>:
push   %rbx
sub    $0x40,%rsp
lea    0xea4(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1213 <log_memory_status+0xc3>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0x10(%rsp),%rax
lea    0x18(%rsp),%r10
lea    0x20(%rsp),%r11
lea    0xe90(%rip),%rsi
lea    0x40(%rsp),%rdx
lea    0x38(%rsp),%rcx
lea    0x30(%rsp),%r8
lea    0x28(%rsp),%r9
mov    %rbx,%rdi
push   %rax
push   %r10
push   %r11
call   1050 <fscanf@plt>
add    $0x20,%rsp
cmp    $0x7,%eax
jne    1213 <log_memory_status+0xc3>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%ecx
mov    0x4(%rsp),%edx
mov    0x38(%rsp),%r8
mov    0x30(%rsp),%r9
sub    $0x8,%rsp
lea    0xe25(%rip),%rsi
push   0x10(%rsp)
push   0x20(%rsp)
push   0x30(%rsp)
push   0x40(%rsp)
push   0x50(%rsp)
call   1060 <fprintf@plt>
add    $0x30,%rsp
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"%ld %ld %ld %ld %ld %ld %ld\00"
@CLOCK_MONOTONIC_RAW = global i32 0
@stderr = global i32 0
@.str.3 = [39 x i8] c"\0A%ld.%09ld %ld %ld %ld %ld %ld %ld %ld\00"
define void @log_memory_status() {
%1 = alloca i32*
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca %struct.timespec
%10 = 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* %10, i32** %1
%11 = load i32*, i32** %1
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %0
br label %37
14: ; preds = %0
%15 = load i32*, i32** %1
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64* %2, i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8)
%17 = icmp ne i32 7, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %37
19: ; preds = %14
%20 = load i32, i32* @CLOCK_MONOTONIC_RAW
%21 = call i32 @clock_gettime(i32 %20, %struct.timespec* %9)
%22 = load i32, i32* @stderr
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i64, i64* %2
%28 = load i64, i64* %3
%29 = load i64, i64* %4
%30 = load i64, i64* %5
%31 = load i64, i64* %6
%32 = load i64, i64* %7
%33 = load i64, i64* %8
%34 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %26, i64 %27, i64 %28, i64 %29, i64 %30, i64 %31, i64 %32, i64 %33)
%35 = load i32*, i32** %1
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %19, %18, %13
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"%ld %ld %ld %ld %ld %ld %ld\00"
@CLOCK_MONOTONIC_RAW = global i32 0
@stderr = global i32 0
@.str.3 = [39 x i8] c"\0A%ld.%09ld %ld %ld %ld %ld %ld %ld %ld\00"
define void @log_memory_status() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca %struct.timespec
%9 = 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))
%10 = icmp eq i32* %9, null
br i1 %10, label %40, label %11
11: ; preds = %0
%12 = bitcast i64* %1 to i8*
%13 = bitcast i64* %2 to i8*
%14 = bitcast i64* %3 to i8*
%15 = bitcast i64* %4 to i8*
%16 = bitcast i64* %5 to i8*
%17 = bitcast i64* %6 to i8*
%18 = bitcast i64* %7 to i8*
%19 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64* %1, i64* %2, i64* %3, i64* %4, i64* %5, i64* %6, i64* %7)
%20 = icmp eq i32 %19, 7
br i1 %20, label %21, label %39
21: ; preds = %11
%22 = bitcast %struct.timespec* %8 to i8*
%23 = load i32, i32* @CLOCK_MONOTONIC_RAW
%24 = call i32 @clock_gettime(i32 %23, %struct.timespec* %8)
%25 = load i32, i32* @stderr
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
%29 = load i32, i32* %28
%30 = load i64, i64* %1
%31 = load i64, i64* %2
%32 = load i64, i64* %3
%33 = load i64, i64* %4
%34 = load i64, i64* %5
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %29, i64 %30, i64 %31, i64 %32, i64 %33, i64 %34, i64 %35, i64 %36)
%38 = call i32 @fclose(i32* %9)
br label %39
39: ; preds = %11, %21
br label %40
40: ; preds = %0, %39
ret void
}