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

/* Variables and functions */
int /*<<< orphan*/ _IOLBF;
int /*<<< orphan*/ fstr(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, float, ...);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sscanf(char *, char *, float *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ sysrq_trigger_oom();
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IOLBF, 0);
  printf("poll_interval=%ds, recovery_interval=%ds, stall_threshold=%d%%\n", 5,
         15, 10);
  while (true) {
    int i;
    char buf[256];
    float full_avg10;
    fstr("/proc/pressure/memory", buf, NULL);
    for (i = 0; buf[i] != '\n'; i++)
      ;
    i++;
    i += 11;
    sscanf(buf + i, "%f", &full_avg10);
    if (false)
      printf("full_avg10=%f\n", full_avg10);
    if (full_avg10 > 10)
      sysrq_trigger_oom();
    else
      sleep(5);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1070 <setvbuf@plt>
lea    0xe6b(%rip),%rdi
movss  0xe5b(%rip),%xmm0
mov    $0xf,%esi
mov    $0xa,%edx
mov    $0x1,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <fstr@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11fc <main+0x9c>
jmp    11ee <main+0x8e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d4 <main+0x74>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xb,%eax
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
lea    0xe3b(%rip),%rsi
lea    -0x124(%rbp),%rdx
call   1050 <sscanf@plt>
movss  -0x124(%rbp),%xmm0
ff
movss  0xdc5(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1254 <main+0xf4>
mov    $0x0,%al
call   1040 <sysrq_trigger_oom@plt>
jmp    125e <main+0xfe>
mov    $0x5,%edi
call   1080 <sleep@plt>
jmp    11b6 <main+0x56>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1070 <setvbuf@plt>
lea    0xe78(%rip),%rdi
movss  0xe68(%rip),%xmm0
mov    $0xf,%esi
mov    $0xa,%edx
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe98(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xea2(%rip),%r12
lea    0xc(%rsp),%rbx
jmp    11d7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <sysrq_trigger_oom@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1060 <fstr@plt>
mov    $0xb,%eax
nopl   0x0(%rax)
cmpb   $0xa,0x5(%rsp,%rax,1)
lea    0x1(%rax),%rax
jne    11f0 <main+0x90>
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <sscanf@plt>
movss  0xc(%rsp),%xmm0
ucomiss 0xde7(%rip),%xmm0
ja     11d0 <main+0x70>
mov    $0x5,%edi
call   1080 <sleep@plt>
jmp    11d7 <main+0x77>

LLVM IR (-O0):
@stdout = global i32 0
@_IOLBF = global i32 0
@.str = [64 x i8] c"poll_interval=%ds, recovery_interval=%ds, stall_threshold=%d%%\0A\00"
@.str.1 = [22 x i8] c"/proc/pressure/memory\00"
@.str.2 = [3 x i8] c"%f\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @stdout
%10 = load i32, i32* @_IOLBF
%11 = call i32 @setvbuf(i32 %9, i32* null, i32 %10, i32 0)
%12 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), float 5.000000e+00, i32 15, i32 10)
br label %13
13: ; preds = %2, %43
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = call i32 @fstr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32* null)
store i32 0, i32* %6
br label %16
16: ; preds = %24, %13
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %27
23: ; preds = %16
br label %24
24: ; preds = %23
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %16
27: ; preds = %16
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 11
store i32 %31, i32* %6
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %8)
%37 = load float, float* %8
%38 = fcmp ogt float %37, 1.000000e+01
br i1 %38, label %39, label %41
39: ; preds = %27
%40 = call i32 (...) @sysrq_trigger_oom()
br label %43
41: ; preds = %27
%42 = call i32 @sleep(i32 5)
br label %43
43: ; preds = %41, %39
br label %13
}

LLVM IR (-O2):
@stdout = global i32 0
@_IOLBF = global i32 0
@.str = [64 x i8] c"poll_interval=%ds, recovery_interval=%ds, stall_threshold=%d%%\0A\00"
@.str.1 = [22 x i8] c"/proc/pressure/memory\00"
@.str.2 = [3 x i8] c"%f\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca float
%5 = load i32, i32* @stdout
%6 = load i32, i32* @_IOLBF
%7 = tail call i32 @setvbuf(i32 %5, i32* null, i32 %6, i32 0)
%8 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), float 5.000000e+00, i32 15, i32 10)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = bitcast float* %4 to i8*
br label %11
11: ; preds = %2, %30
%12 = call i32 @fstr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32* null)
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ %18, %13 ], [ 0, %11 ]
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
%18 = add nuw i64 %14, 1
br i1 %17, label %19, label %13
19: ; preds = %13
%20 = add i64 %14, 12
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%24 = load float, float* %4
%25 = fcmp ogt float %24, 1.000000e+01
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 (...) @sysrq_trigger_oom()
br label %30
28: ; preds = %19
%29 = call i32 @sleep(i32 5)
br label %30
30: ; preds = %28, %26
br label %11
}