#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 MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_LOCKED;
int MAP_PRIVATE;
int /*<<< orphan*/ O_WRONLY;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fsync(int);
int getpagesize();
int getpid();
char *mmap(int /*<<< orphan*/ *, int, int, int, int /*<<< orphan*/,
           int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  char buf[10];
  int i;
  int loop;
  int pid;
  int size = getpagesize();
  int fd = open("memcg/0/tasks", O_WRONLY);
  if (fd < 0)
    return 1;
  for (loop = 0; loop < 40; loop++) {
    for (i = 0; i < 10; i++) {
      pid = fork();
      if (pid == 0) {
        char *p;
        sprintf(buf, "%d", getpid());
        write(fd, buf, 10);
        fsync(fd);
        p = mmap(NULL, size, PROT_READ | PROT_WRITE,
                 (MAP_PRIVATE | MAP_ANONYMOUS | MAP_LOCKED), 0, 0);
        if (p == MAP_FAILED) {
          perror("mmap failed");
          exit(1);
        } else
          exit(0);
      }
    }
    for (i = 0; i < 10; i++)
      wait(NULL);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <getpagesize@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    0xe17(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1207 <main+0x47>
movl   $0x1,-0x4(%rbp)
jmp    1348 <main+0x188>
movl   $0x0,-0x18(%rbp)
cmpl   $0x28,-0x18(%rbp)
jge    1339 <main+0x179>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    12fe <main+0x13e>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12eb <main+0x12b>
lea    -0xe(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xdb5(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x24(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1070 <fsync@plt>
mov    -0x20(%rbp),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
mov    0x2d3e(%rip),%rax
or     (%rax),%edx
mov    0x2d2d(%rip),%rax
mov    (%rax),%ecx
mov    0x2d44(%rip),%rax
or     (%rax),%ecx
mov    0x2d2b(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1050 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2cf3(%rip),%rcx
cmp    (%rcx),%rax
jne    12e4 <main+0x124>
lea    0xd3c(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    12f0 <main+0x130>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121f <main+0x5f>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1326 <main+0x166>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1305 <main+0x145>
jmp    132b <main+0x16b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120e <main+0x4e>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   10a0 <getpagesize@plt>
mov    %eax,%r15d
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     12e8 <main+0x128>
mov    %eax,%ebp
mov    $0x28,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12f8 <main+0x138>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
add    $0xffffffff,%ebx
jne    1200 <main+0x40>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    12ed <main+0x12d>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd08(%rip),%rsi
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%edx
call   10b0 <sprintf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1070 <fsync@plt>
mov    0x2cc6(%rip),%rax
mov    0x2c8f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c7c(%rip),%rax
mov    0x2c95(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c7a(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    %r15d,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    0x2c49(%rip),%rcx
cmp    (%rcx),%rax
jne    138a <main+0x1ca>
lea    0xc96(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"memcg/0/tasks\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_LOCKED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [12 x i8] c"mmap failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %1
%9 = call i32 (...) @getpagesize()
store i32 %9, i32* %6
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %0
store i32 1, i32* %1
br label %74
15: ; preds = %0
store i32 0, i32* %4
br label %16
16: ; preds = %68, %15
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 40
br i1 %18, label %19, label %71
19: ; preds = %16
store i32 0, i32* %3
br label %20
20: ; preds = %55, %19
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %58
23: ; preds = %20
%24 = call i32 (...) @fork()
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %54
27: ; preds = %23
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%29 = call i32 (...) @getpid()
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%33 = call i32 @write(i32 %31, i8* %32, i32 10)
%34 = load i32, i32* %7
%35 = call i32 @fsync(i32 %34)
%36 = load i32, i32* %6
%37 = load i32, i32* @PROT_READ
%38 = load i32, i32* @PROT_WRITE
%39 = or i32 %37, %38
%40 = load i32, i32* @MAP_PRIVATE
%41 = load i32, i32* @MAP_ANONYMOUS
%42 = or i32 %40, %41
%43 = load i32, i32* @MAP_LOCKED
%44 = or i32 %42, %43
%45 = call i8* @mmap(i32* null, i32 %36, i32 %39, i32 %44, i32 0, i32 0)
store i8* %45, i8** %8
%46 = load i8*, i8** %8
%47 = load i8*, i8** @MAP_FAILED
%48 = icmp eq i8* %46, %47
br i1 %48, label %49, label %52
49: ; preds = %27
%50 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %27
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %23
br label %55
55: ; preds = %54
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %20
58: ; preds = %20
store i32 0, i32* %3
br label %59
59: ; preds = %64, %58
%60 = load i32, i32* %3
%61 = icmp slt i32 %60, 10
br i1 %61, label %62, label %67
62: ; preds = %59
%63 = call i32 @wait(i32* null)
br label %64
64: ; preds = %62
%65 = load i32, i32* %3
%66 = add nsw i32 %65, 1
store i32 %66, i32* %3
br label %59
67: ; preds = %59
br label %68
68: ; preds = %67
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %16
71: ; preds = %16
%72 = load i32, i32* %7
%73 = call i32 @close(i32 %72)
store i32 0, i32* %1
br label %74
74: ; preds = %71, %14
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
@.str = [14 x i8] c"memcg/0/tasks\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_LOCKED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [12 x i8] c"mmap failed\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getpagesize()
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %74, label %7
7: ; preds = %0, %38
%8 = phi i32 [ %49, %38 ], [ 0, %0 ]
%9 = tail call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %51, label %11
11: ; preds = %7
%12 = tail call i32 (...) @fork()
%13 = icmp eq i32 %12, 0
br i1 %13, label %51, label %14
14: ; preds = %11
%15 = tail call i32 (...) @fork()
%16 = icmp eq i32 %15, 0
br i1 %16, label %51, label %17
17: ; preds = %14
%18 = tail call i32 (...) @fork()
%19 = icmp eq i32 %18, 0
br i1 %19, label %51, label %20
20: ; preds = %17
%21 = tail call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %51, label %23
23: ; preds = %20
%24 = tail call i32 (...) @fork()
%25 = icmp eq i32 %24, 0
br i1 %25, label %51, label %26
26: ; preds = %23
%27 = tail call i32 (...) @fork()
%28 = icmp eq i32 %27, 0
br i1 %28, label %51, label %29
29: ; preds = %26
%30 = tail call i32 (...) @fork()
%31 = icmp eq i32 %30, 0
br i1 %31, label %51, label %32
32: ; preds = %29
%33 = tail call i32 (...) @fork()
%34 = icmp eq i32 %33, 0
br i1 %34, label %51, label %35
35: ; preds = %32
%36 = tail call i32 (...) @fork()
%37 = icmp eq i32 %36, 0
br i1 %37, label %51, label %38
38: ; preds = %35
%39 = tail call i32 @wait(i32* null)
%40 = tail call i32 @wait(i32* null)
%41 = tail call i32 @wait(i32* null)
%42 = tail call i32 @wait(i32* null)
%43 = tail call i32 @wait(i32* null)
%44 = tail call i32 @wait(i32* null)
%45 = tail call i32 @wait(i32* null)
%46 = tail call i32 @wait(i32* null)
%47 = tail call i32 @wait(i32* null)
%48 = tail call i32 @wait(i32* null)
%49 = add nuw nsw i32 %8, 1
%50 = icmp eq i32 %49, 40
br i1 %50, label %72, label %7
51: ; preds = %35, %32, %29, %26, %23, %20, %17, %14, %11, %7
%52 = tail call i32 (...) @getpid()
%53 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = call i32 @write(i32 %5, i8* %2, i32 10)
%55 = tail call i32 @fsync(i32 %5)
%56 = load i32, i32* @PROT_READ
%57 = load i32, i32* @PROT_WRITE
%58 = or i32 %57, %56
%59 = load i32, i32* @MAP_PRIVATE
%60 = load i32, i32* @MAP_ANONYMOUS
%61 = or i32 %60, %59
%62 = load i32, i32* @MAP_LOCKED
%63 = or i32 %61, %62
%64 = tail call i8* @mmap(i32* null, i32 %3, i32 %58, i32 %63, i32 0, i32 0)
%65 = load i8*, i8** @MAP_FAILED
%66 = icmp eq i8* %64, %65
br i1 %66, label %67, label %70
67: ; preds = %51
%68 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%69 = tail call i32 @exit(i32 1)
unreachable
70: ; preds = %51
%71 = tail call i32 @exit(i32 0)
unreachable
72: ; preds = %38
%73 = tail call i32 @close(i32 %5)
br label %74
74: ; preds = %0, %72
%75 = phi i32 [ 0, %72 ], [ 1, %0 ]
ret i32 %75
}