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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CLOEXEC;
int O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int openat(int, char *, int);
scalar_t__ pidfd_clone(int, int *);
int pidfd_metadata_fd(scalar_t__, int);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
scalar_t__ write(int /*<<< orphan*/, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int pidfd = 0, ret = EXIT_FAILURE;
  char buf[4096] = {0};
  pid_t pid;
  int procfd, statusfd;
  ssize_t bytes;
  pid = pidfd_clone(0x00001000, &pidfd);
  if (pid < 0)
    exit(ret);
  procfd = pidfd_metadata_fd(pid, pidfd);
  close(pidfd);
  if (procfd < 0)
    goto out;
  statusfd = openat(procfd, "status", O_RDONLY | O_CLOEXEC);
  close(procfd);
  if (statusfd < 0)
    goto out;
  bytes = read(statusfd, buf, sizeof(buf));
  if (bytes > 0)
    bytes = write(STDOUT_FILENO, buf, bytes);
  close(statusfd);
  ret = EXIT_SUCCESS;
out:
  (void)wait(NULL);
  exit(ret);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    $0x1000,%edi
lea    -0x14(%rbp),%rsi
call   1080 <pidfd_clone@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jge    11fa <main+0x6a>
mov    -0x18(%rbp),%edi
call   1090 <exit@plt>
mov    -0x1028(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <pidfd_metadata_fd@plt>
mov    %eax,-0x102c(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x102c(%rbp)
jge    1229 <main+0x99>
jmp    12d6 <main+0x146>
mov    -0x102c(%rbp),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
mov    0x2d79(%rip),%rax
or     (%rax),%edx
lea    0xdb8(%rip),%rsi
call   1040 <openat@plt>
mov    %eax,-0x1030(%rbp)
mov    -0x102c(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x1030(%rbp)
jge    1270 <main+0xe0>
jmp    12d6 <main+0x146>
mov    -0x1030(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %rax,-0x1038(%rbp)
cmpq   $0x0,-0x1038(%rbp)
jle    12bf <main+0x12f>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1038(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x1038(%rbp)
mov    -0x1030(%rbp),%edi
call   1060 <close@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
mov    -0x18(%rbp),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1010,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2e26(%rip),%rax
mov    (%rax),%ebx
lea    0x10(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xc(%rsp),%rsi
mov    $0x1000,%edi
call   1080 <pidfd_clone@plt>
test   %rax,%rax
js     1264 <main+0xd4>
mov    0xc(%rsp),%esi
mov    %rax,%rdi
call   10b0 <pidfd_metadata_fd@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   1060 <close@plt>
test   %ebp,%ebp
js     125d <main+0xcd>
mov    0x2de9(%rip),%rax
mov    0x2dba(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xdf7(%rip),%rsi
mov    %ebp,%edi
call   1040 <openat@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1060 <close@plt>
test   %r14d,%r14d
js     125d <main+0xcd>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    124c <main+0xbc>
mov    0x2db3(%rip),%rcx
mov    (%rcx),%edi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10a0 <wait@plt>
mov    %ebx,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [7 x i8] c"status\00"
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %7
%14 = bitcast [4096 x i8]* %8 to i8*
%15 = call i64 @pidfd_clone(i32 4096, i32* %6)
store i64 %15, i64* %9
%16 = load i64, i64* %9
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* %7
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i64, i64* %9
%23 = load i32, i32* %6
%24 = call i32 @pidfd_metadata_fd(i64 %22, i32 %23)
store i32 %24, i32* %10
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %21
br label %56
30: ; preds = %21
%31 = load i32, i32* %10
%32 = load i32, i32* @O_RDONLY
%33 = load i32, i32* @O_CLOEXEC
%34 = or i32 %32, %33
%35 = call i32 @openat(i32 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %34)
store i32 %35, i32* %11
%36 = load i32, i32* %10
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %11
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %30
br label %56
41: ; preds = %30
%42 = load i32, i32* %11
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%44 = call i64 @read(i32 %42, i8* %43, i32 4096)
store i64 %44, i64* %12
%45 = load i64, i64* %12
%46 = icmp sgt i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %41
%48 = load i32, i32* @STDOUT_FILENO
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%50 = load i64, i64* %12
%51 = call i64 @write(i32 %48, i8* %49, i64 %50)
store i64 %51, i64* %12
br label %52
52: ; preds = %47, %41
%53 = load i32, i32* %11
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* @EXIT_SUCCESS
store i32 %55, i32* %7
br label %56
56: ; preds = %52, %40, %29
%57 = call i32 @wait(i32* null)
%58 = load i32, i32* %7
%59 = call i32 @exit(i32 %58)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [7 x i8] c"status\00"
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = load i32, i32* @EXIT_FAILURE
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = call i64 @pidfd_clone(i32 4096, i32* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @exit(i32 %6)
unreachable
12: ; preds = %2
%13 = load i32, i32* %3
%14 = call i32 @pidfd_metadata_fd(i64 %8, i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @close(i32 %15)
%17 = icmp slt i32 %14, 0
br i1 %17, label %34, label %18
18: ; preds = %12
%19 = load i32, i32* @O_RDONLY
%20 = load i32, i32* @O_CLOEXEC
%21 = or i32 %20, %19
%22 = call i32 @openat(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = call i32 @close(i32 %14)
%24 = icmp slt i32 %22, 0
br i1 %24, label %34, label %25
25: ; preds = %18
%26 = call i64 @read(i32 %22, i8* %7, i32 4096)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @STDOUT_FILENO
%30 = call i64 @write(i32 %29, i8* %7, i64 %26)
br label %31
31: ; preds = %28, %25
%32 = call i32 @close(i32 %22)
%33 = load i32, i32* @EXIT_SUCCESS
br label %34
34: ; preds = %18, %12, %31
%35 = phi i32 [ %6, %12 ], [ %6, %18 ], [ %33, %31 ]
%36 = call i32 @wait(i32* null)
%37 = call i32 @exit(i32 %35)
unreachable
}