#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*/ MADV_RANDOM;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SIGSTOP;
int /*<<< orphan*/ close(int);
scalar_t__ ftruncate(int, unsigned long);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ madvise(char *, unsigned long, int /*<<< orphan*/);
int mkstemp(char *);
char *mmap(int /*<<< orphan*/ *, unsigned long, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ unlink(char *);
int start_process(unsigned long nr_bytes) {
  char filename[] = "/tmp/clog-XXXXXX";
  unsigned long i;
  char *map;
  int fd;
  fd = mkstemp(filename);
  unlink(filename);
  if (fd == -1) {
    perror("mkstemp()");
    return -1;
  }
  if (ftruncate(fd, nr_bytes)) {
    perror("ftruncate()");
    return -1;
  }
  map = mmap(NULL, nr_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (map == MAP_FAILED) {
    perror("mmap()");
    return -1;
  }
  if (madvise(map, nr_bytes, MADV_RANDOM)) {
    perror("madvise()");
    return -1;
  }
  kill(getpid(), SIGSTOP);
  for (i = 0; i < nr_bytes; i += 4096)
    ((volatile char *)map)[i];
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<start_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xe5d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe58(%rip),%al
mov    %al,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
call   1090 <mkstemp@plt>
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
cmpl   $0xffffffff,-0x44(%rbp)
jne    11f2 <start_process+0x62>
lea    0xe30(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <start_process+0x181>
mov    -0x44(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <ftruncate@plt>
cmp    $0x0,%rax
je     1220 <start_process+0x90>
lea    0xe0c(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <start_process+0x181>
mov    -0x10(%rbp),%rsi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    0x2d94(%rip),%rax
or     (%rax),%edx
mov    0x2dab(%rip),%rax
mov    (%rax),%ecx
mov    -0x44(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2d62(%rip),%rcx
cmp    (%rcx),%rax
jne    127f <start_process+0xef>
lea    0xdb9(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <start_process+0x181>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d42(%rip),%rax
mov    (%rax),%edx
call   10a0 <madvise@plt>
cmp    $0x0,%rax
je     12b7 <start_process+0x127>
lea    0xd88(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <start_process+0x181>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1302 <start_process+0x172>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x38(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x38(%rbp)
jmp    12d6 <start_process+0x146>
mov    -0x44(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_process>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movaps 0xe5c(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1090 <mkstemp@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%r14d
je     127a <start_process+0xea>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1060 <ftruncate@plt>
test   %rax,%rax
jne    1283 <start_process+0xf3>
mov    0x2e10(%rip),%rax
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dee(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
mov    0x2daa(%rip),%rax
cmp    (%rax),%rbp
je     128c <start_process+0xfc>
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <madvise@plt>
test   %rax,%rax
jne    1295 <start_process+0x105>
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    0x2d73(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1080 <kill@plt>
test   %rbx,%rbx
je     1270 <start_process+0xe0>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x0(%rbp,%rax,1),%ecx
add    $0x1000,%rax
cmp    %rbx,%rax
jb     1260 <start_process+0xd0>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    12a7 <start_process+0x117>
lea    0xd90(%rip),%rdi
jmp    129c <start_process+0x10c>
lea    0xd91(%rip),%rdi
jmp    129c <start_process+0x10c>
lea    0xd94(%rip),%rdi
jmp    129c <start_process+0x10c>
lea    0xd92(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.start_process.filename = [17 x i8] c"/tmp/clog-XXXXXX\00"
@.str = [10 x i8] c"mkstemp()\00"
@.str.1 = [12 x i8] c"ftruncate()\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [7 x i8] c"mmap()\00"
@MADV_RANDOM = global i32 0
@.str.3 = [10 x i8] c"madvise()\00"
@SIGSTOP = global i32 0
define i32 @start_process(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca [17 x i8]
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i64 %0, i64* %3
%8 = bitcast [17 x i8]* %4 to i8*
%9 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%10 = call i32 @mkstemp(i8* %9)
store i32 %10, i32* %7
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%12 = call i32 @unlink(i8* %11)
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %64
17: ; preds = %1
%18 = load i32, i32* %7
%19 = load i64, i64* %3
%20 = call i64 @ftruncate(i32 %18, i64 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %64
24: ; preds = %17
%25 = load i64, i64* %3
%26 = load i32, i32* @PROT_READ
%27 = load i32, i32* @PROT_WRITE
%28 = or i32 %26, %27
%29 = load i32, i32* @MAP_SHARED
%30 = load i32, i32* %7
%31 = call i8* @mmap(i32* null, i64 %25, i32 %28, i32 %29, i32 %30, i32 0)
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = load i8*, i8** @MAP_FAILED
%34 = icmp eq i8* %32, %33
br i1 %34, label %35, label %37
35: ; preds = %24
%36 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %64
37: ; preds = %24
%38 = load i8*, i8** %6
%39 = load i64, i64* %3
%40 = load i32, i32* @MADV_RANDOM
%41 = call i64 @madvise(i8* %38, i64 %39, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %64
45: ; preds = %37
%46 = call i32 (...) @getpid()
%47 = load i32, i32* @SIGSTOP
%48 = call i32 @kill(i32 %46, i32 %47)
store i64 0, i64* %5
br label %49
49: ; preds = %58, %45
%50 = load i64, i64* %5
%51 = load i64, i64* %3
%52 = icmp ult i64 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = load i8*, i8** %6
%55 = load i64, i64* %5
%56 = getelementptr inbounds i8, i8* %54, i64 %55
%57 = load volatile i8, i8* %56
br label %58
58: ; preds = %53
%59 = load i64, i64* %5
%60 = add i64 %59, 4096
store i64 %60, i64* %5
br label %49
61: ; preds = %49
%62 = load i32, i32* %7
%63 = call i32 @close(i32 %62)
store i32 0, i32* %2
br label %64
64: ; preds = %61, %43, %35, %22, %15
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
@__const.start_process.filename = [17 x i8] c"/tmp/clog-XXXXXX\00"
@.str = [10 x i8] c"mkstemp()\00"
@.str.1 = [12 x i8] c"ftruncate()\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [7 x i8] c"mmap()\00"
@MADV_RANDOM = global i32 0
@.str.3 = [10 x i8] c"madvise()\00"
@SIGSTOP = global i32 0
define i32 @start_process(i64 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = call i32 @mkstemp(i8* %3)
%5 = call i32 @unlink(i8* %3)
%6 = icmp eq i32 %4, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %43
9: ; preds = %1
%10 = call i64 @ftruncate(i32 %4, i64 %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %43
14: ; preds = %9
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @PROT_WRITE
%17 = or i32 %16, %15
%18 = load i32, i32* @MAP_SHARED
%19 = call i8* @mmap(i32* null, i64 %0, i32 %17, i32 %18, i32 %4, i32 0)
%20 = load i8*, i8** @MAP_FAILED
%21 = icmp eq i8* %19, %20
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %43
24: ; preds = %14
%25 = load i32, i32* @MADV_RANDOM
%26 = call i64 @madvise(i8* %19, i64 %0, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %43
30: ; preds = %24
%31 = call i32 (...) @getpid()
%32 = load i32, i32* @SIGSTOP
%33 = call i32 @kill(i32 %31, i32 %32)
%34 = icmp eq i64 %0, 0
br i1 %34, label %41, label %35
35: ; preds = %30, %35
%36 = phi i64 [ %39, %35 ], [ 0, %30 ]
%37 = getelementptr inbounds i8, i8* %19, i64 %36
%38 = load volatile i8, i8* %37
%39 = add i64 %36, 4096
%40 = icmp ult i64 %39, %0
br i1 %40, label %35, label %41
41: ; preds = %35, %30
%42 = call i32 @close(i32 %4)
br label %43
43: ; preds = %41, %28, %22, %12, %7
%44 = phi i32 [ -1, %7 ], [ -1, %12 ], [ -1, %22 ], [ -1, %28 ], [ 0, %41 ]
ret i32 %44
}