#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
char *malloc(int);
int /*<<< orphan*/ *stderr;
int main() {
  FILE *oom_score_adj = fopen("/proc/self/oom_score_adj", "w");
  if (oom_score_adj) {
    fprintf(oom_score_adj, "1000\n");
    fclose(oom_score_adj);
  } else {
    FILE *oom_adj = fopen("/proc/self/oom_adj", "w");
    if (oom_adj) {
      fprintf(oom_adj, "15\n");
      fclose(oom_adj);
    } else {
      fprintf(stderr, "Failed to raise OOM score\n");
      fprintf(stderr, "Are you fast enough to ^C before the havoc begins?\n");
    }
  }
  for (;;) {
    char *c = malloc(655360);
    int i;
    for (i = 0; i < 655360; ++i) {
      c[i] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118f <main+0x4f>
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1200 <main+0xc0>
lea    0xe8b(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cf <main+0x8f>
mov    -0x18(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11fb <main+0xbb>
mov    0x2e0a(%rip),%rax
mov    (%rax),%rdi
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1200 <main+0xc0>
jmp    1205 <main+0xc5>
mov    $0xa0000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xa0000,-0x24(%rbp)
jge    1241 <main+0x101>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    121a <main+0xda>
jmp    1205 <main+0xc5>

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
lea    0xeda(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     115a <main+0x2a>
mov    %rax,%rbx
lea    0xec8(%rip),%rdi
mov    $0x5,%esi
jmp    1181 <main+0x51>
lea    0xec0(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     11a2 <main+0x72>
mov    %rax,%rbx
lea    0xeb8(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cs nopw 0x0(%rax,%rax,1)
jmp    11a0 <main+0x70>
mov    0x2e37(%rip),%rbx
mov    (%rbx),%rcx
lea    0xe85(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    (%rbx),%rcx
lea    0xe87(%rip),%rdi
mov    $0x33,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
jmp    11a0 <main+0x70>

LLVM IR (-O0):
@.str = [25 x i8] c"/proc/self/oom_score_adj\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"1000\0A\00"
@.str.3 = [19 x i8] c"/proc/self/oom_adj\00"
@.str.4 = [4 x i8] c"15\0A\00"
@stderr = global i32* null
@.str.5 = [27 x i8] c"Failed to raise OOM score\0A\00"
@.str.6 = [52 x i8] c"Are you fast enough to ^C before the havoc begins?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 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 = icmp ne i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32*, i32** %2
%13 = call i32 @fclose(i32* %12)
br label %29
14: ; preds = %0
%15 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32*, i32** %3
%20 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
br label %28
23: ; preds = %14
%24 = load i32*, i32** @stderr
%25 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32*, i32** @stderr
%27 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
br label %28
28: ; preds = %23, %18
br label %29
29: ; preds = %28, %9
br label %30
30: ; preds = %43, %29
%31 = call i8* @malloc(i32 655360)
store i8* %31, i8** %4
store i32 0, i32* %5
br label %32
32: ; preds = %40, %30
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 655360
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %35
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %32
43: ; preds = %32
br label %30
}

LLVM IR (-O2):
@.str = [25 x i8] c"/proc/self/oom_score_adj\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"1000\0A\00"
@.str.3 = [19 x i8] c"/proc/self/oom_adj\00"
@.str.4 = [4 x i8] c"15\0A\00"
@stderr = global i32* null
@.str.5 = [27 x i8] c"Failed to raise OOM score\0A\00"
@.str.6 = [52 x i8] c"Are you fast enough to ^C before the havoc begins?\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5, i64 1, i32* %1)
%5 = tail call i32 @fclose(i32* %1)
br label %17
6: ; preds = %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 3, i64 1, i32* %7)
%11 = tail call i32 @fclose(i32* %7)
br label %17
12: ; preds = %6
%13 = load i32*, i32** @stderr
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i64 26, i64 1, i32* %13)
%15 = load i32*, i32** @stderr
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i64 51, i64 1, i32* %15)
br label %17
17: ; preds = %9, %12, %3
br label %18
18: ; preds = %17, %18
br label %18
}