#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EBADE;
int /*<<< orphan*/ ESRCH;
int atoi(char *);
scalar_t__ check_resp(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/);
int criu_dump();
int /*<<< orphan*/ criu_set_pid(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ get_base_req();
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int no_process(void) {
  FILE *f = NULL;
  size_t len;
  ssize_t count;
  char *buf = NULL;
  int pid, fd, ret;
  printf("--- Try to dump unexisting process\n");
  f = fopen("/proc/sys/kernel/pid_max", "r");
  if (!f) {
    perror("Can't open "
           "/proc/sys/kernel/pid_max");
    goto err;
  }
  count = getline(&buf, &len, f);
  if (count == -1) {
    perror("Can't read "
           "/proc/sys/kernel/pid_max");
    goto err;
  }
  pid = atoi(buf);
  if (!kill(pid, 0)) {
    fprintf(stderr, "max pid is taken\n");
    goto err;
  }
  get_base_req();
  criu_set_pid(pid);
  ret = criu_dump();
  if (check_resp(ret, -EBADE, errno, ESRCH))
    goto err;
  printf("   `- Success\n");
  return 0;
err:
  if (f)
    fclose(f);
  return -1;
}


x86 assembly (clang, -O0):
<no_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe21(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6a(%rip),%rdi
lea    0xe32(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1217 <no_process+0x57>
lea    0xe19(%rip),%rdi
call   10c0 <perror@plt>
jmp    12e4 <no_process+0x124>
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10e0 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1246 <no_process+0x86>
lea    0xe0e(%rip),%rdi
call   10c0 <perror@plt>
jmp    12e4 <no_process+0x124>
mov    -0x28(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
xor    %esi,%esi
call   1070 <kill@plt>
cmp    $0x0,%eax
jne    127f <no_process+0xbf>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12e4 <no_process+0x124>
mov    $0x0,%al
call   10a0 <get_base_req@plt>
mov    -0x2c(%rbp),%edi
call   1030 <criu_set_pid@plt>
mov    $0x0,%al
call   1090 <criu_dump@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
xor    %esi,%esi
mov    0x2d44(%rip),%rax
sub    (%rax),%esi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
mov    0x2d0a(%rip),%rax
mov    (%rax),%ecx
call   1080 <check_resp@plt>
cmp    $0x0,%rax
je     12cc <no_process+0x10c>
jmp    12e4 <no_process+0x124>
lea    0xdad(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ff <no_process+0x13f>
cmpq   $0x0,-0x10(%rbp)
je     12f8 <no_process+0x138>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<no_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4e(%rip),%rdi
lea    0xe16(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12a7 <no_process+0xe7>
mov    %rax,%r14
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   10e0 <getline@plt>
cmp    $0xffffffff,%eax
je     12b5 <no_process+0xf5>
mov    (%rsp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebx
xor    %ebp,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1070 <kill@plt>
test   %eax,%eax
je     127c <no_process+0xbc>
xor    %eax,%eax
call   10a0 <get_base_req@plt>
mov    %ebx,%edi
call   1030 <criu_set_pid@plt>
xor    %eax,%eax
call   1090 <criu_dump@plt>
mov    0x2d9e(%rip),%rcx
sub    (%rcx),%ebp
mov    0x2d7d(%rip),%rcx
mov    (%rcx),%edx
mov    0x2d64(%rip),%rcx
mov    (%rcx),%ecx
mov    %eax,%edi
mov    %ebp,%esi
call   1080 <check_resp@plt>
test   %rax,%rax
jne    1291 <no_process+0xd1>
lea    0xe0c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    129e <no_process+0xde>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd54(%rip),%rdi
call   10c0 <perror@plt>
jmp    1299 <no_process+0xd9>
lea    0xd6a(%rip),%rdi
call   10c0 <perror@plt>
jmp    1291 <no_process+0xd1>

LLVM IR (-O0):
@.str = [36 x i8] c"--- Try to dump unexisting process\0A\00"
@.str.1 = [25 x i8] c"/proc/sys/kernel/pid_max\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [36 x i8] c"Can't open /proc/sys/kernel/pid_max\00"
@.str.4 = [36 x i8] c"Can't read /proc/sys/kernel/pid_max\00"
@stderr = global i32 0
@.str.5 = [18 x i8] c"max pid is taken\0A\00"
@EBADE = global i32 0
@errno = global i32 0
@ESRCH = global i32 0
@.str.6 = [15 x i8] c" `- Success\0A\00"
define i32 @no_process() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* null, i32** %2
store i8* null, i8** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %46
15: ; preds = %0
%16 = load i32*, i32** %2
%17 = call i32 @getline(i8** %5, i64* %3, i32* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %46
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = call i32 @kill(i32 %25, i32 0)
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %46
31: ; preds = %22
%32 = call i32 (...) @get_base_req()
%33 = load i32, i32* %6
%34 = call i32 @criu_set_pid(i32 %33)
%35 = call i32 (...) @criu_dump()
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = load i32, i32* @EBADE
%38 = sub nsw i32 0, %37
%39 = load i32, i32* @errno
%40 = load i32, i32* @ESRCH
%41 = call i64 @check_resp(i32 %36, i32 %38, i32 %39, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %31
br label %46
44: ; preds = %31
%45 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %53
46: ; preds = %43, %28, %20, %13
%47 = load i32*, i32** %2
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32*, i32** %2
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %49, %46
store i32 -1, i32* %1
br label %53
53: ; preds = %52, %44
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"/proc/sys/kernel/pid_max\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [36 x i8] c"Can't open /proc/sys/kernel/pid_max\00"
@.str.4 = [36 x i8] c"Can't read /proc/sys/kernel/pid_max\00"
@stderr = global i32 0
@.str.5 = [18 x i8] c"max pid is taken\0A\00"
@EBADE = global i32 0
@errno = global i32 0
@ESRCH = global i32 0
@str = [35 x i8] c"--- Try to dump unexisting process\00"
@str.7 = [14 x i8] c" `- Success\00"
define i32 @no_process() {
%1 = alloca i64
%2 = alloca i8*
%3 = bitcast i64* %1 to i8*
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %33, label %8
8: ; preds = %0
%9 = call i32 @getline(i8** %2, i64* %1, i32* %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %35
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i32 @atoi(i8* %14)
%16 = call i32 @kill(i32 %15, i32 0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %35
21: ; preds = %13
%22 = call i32 (...) @get_base_req()
%23 = call i32 @criu_set_pid(i32 %15)
%24 = call i32 (...) @criu_dump()
%25 = load i32, i32* @EBADE
%26 = sub nsw i32 0, %25
%27 = load i32, i32* @errno
%28 = load i32, i32* @ESRCH
%29 = call i64 @check_resp(i32 %24, i32 %26, i32 %27, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %21
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %37
33: ; preds = %0
%34 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %37
35: ; preds = %21, %18, %11
%36 = call i32 @fclose(i32* %6)
br label %37
37: ; preds = %33, %35, %31
%38 = phi i32 [ 0, %31 ], [ -1, %35 ], [ -1, %33 ]
ret i32 %38
}