#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 */
scalar_t__ KCMP_FILE;
scalar_t__ KCMP_FILES;
scalar_t__ KCMP_FS;
scalar_t__ KCMP_IO;
scalar_t__ KCMP_SIGHAND;
scalar_t__ KCMP_SYSVSEM;
scalar_t__ KCMP_TYPES;
scalar_t__ KCMP_VM;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ P_ALL;
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sys_kcmp(int, int, scalar_t__, int, int);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  const char kpath[] = "kcmp-test-file";
  int pid1, pid2;
  int fd1, fd2;
  int status;
  fd1 = open(kpath, O_RDWR | O_CREAT | O_TRUNC, 0644);
  pid1 = getpid();
  if (fd1 < 0) {
    perror("Can't create file");
    exit(1);
  }
  pid2 = fork();
  if (pid2 < 0) {
    perror("fork failed");
    exit(1);
  }
  if (!pid2) {
    int pid2 = getpid();
    int ret;
    fd2 = open(kpath, O_RDWR, 0644);
    if (fd2 < 0) {
      perror("Can't open file");
      exit(1);
    }
    printf("pid1: %6d pid2: %6d FD: %2ld FILES: %2ld VM: %2ld "
           "FS: %2ld SIGHAND: %2ld IO: %2ld SYSVSEM: %2ld "
           "INV: %2ld\n",
           pid1, pid2, sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd2),
           sys_kcmp(pid1, pid2, KCMP_FILES, 0, 0),
           sys_kcmp(pid1, pid2, KCMP_VM, 0, 0),
           sys_kcmp(pid1, pid2, KCMP_FS, 0, 0),
           sys_kcmp(pid1, pid2, KCMP_SIGHAND, 0, 0),
           sys_kcmp(pid1, pid2, KCMP_IO, 0, 0),
           sys_kcmp(pid1, pid2, KCMP_SYSVSEM, 0, 0),
           sys_kcmp(pid1, pid2, KCMP_TYPES + 1, 0, 0));
    ret = sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd1);
    if (ret) {
      printf("FAIL: 0 expected but %d returned\n", ret);
      ret = -1;
    } else
      printf("PASS: 0 returned as expected\n");
    ret = sys_kcmp(pid1, pid1, KCMP_VM, 0, 0);
    if (ret) {
      printf("FAIL: 0 expected but %li returned\n", ret);
      ret = -1;
    } else
      printf("PASS: 0 returned as expected\n");
    exit(ret);
  }
  waitpid(pid2, &status, P_ALL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
movl   $0x0,-0x14(%rbp)
mov    %edi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    0xe5d(%rip),%rax
mov    %rax,-0x2f(%rbp)
mov    0xe5b(%rip),%eax
mov    %eax,-0x27(%rbp)
mov    0xe55(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe4d(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x2f(%rbp),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
mov    0x2e0f(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    121a <main+0x9a>
lea    0xe04(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1244 <main+0xc4>
lea    0xdec(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x38(%rbp)
jne    147b <main+0x2fb>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x48(%rbp)
lea    -0x2f(%rbp),%rdi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1292 <main+0x112>
lea    0xdaa(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2d05(%rip),%rax
mov    (%rax),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,-0x60(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2cc6(%rip),%rax
mov    (%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2cc0(%rip),%rax
mov    (%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    %eax,-0x58(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2c92(%rip),%rax
mov    (%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    %eax,%r14d
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2c64(%rip),%rax
mov    (%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    %eax,%ebx
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2c77(%rip),%rax
mov    (%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    %eax,-0x54(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2c89(%rip),%rax
mov    (%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    %eax,-0x50(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2c4b(%rip),%rax
mov    (%rax),%rdx
add    $0x1,%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    -0x68(%rbp),%esi
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%ecx
mov    -0x5c(%rbp),%r8d
mov    -0x58(%rbp),%r9d
mov    -0x54(%rbp),%r11d
mov    -0x50(%rbp),%r10d
lea    0xc8e(%rip),%rdi
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    0x2bd7(%rip),%rax
mov    (%rax),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1412 <main+0x292>
mov    -0x4c(%rbp),%esi
lea    0xca9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4c(%rbp)
jmp    1420 <main+0x2a0>
lea    0xcb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    0x2b7b(%rip),%rax
mov    (%rax),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_kcmp@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1465 <main+0x2e5>
mov    -0x4c(%rbp),%esi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4c(%rbp)
jmp    1473 <main+0x2f3>
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%edi
mov    0x2b1b(%rip),%rax
mov    (%rax),%edx
lea    -0x44(%rbp),%rsi
call   1060 <waitpid@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movabs $0x656c69662d7473,%rax
mov    %rax,0x1f(%rsp)
movabs $0x7365742d706d636b,%rax
74 65 73
mov    0x2e12(%rip),%rbx
mov    0x2e33(%rip),%rcx
mov    (%rcx),%esi
or     (%rbx),%esi
mov    %rax,0x18(%rsp)
mov    0x2e1b(%rip),%rax
or     (%rax),%esi
lea    0x18(%rsp),%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getpid@plt>
test   %ebp,%ebp
js     1229 <main+0x99>
mov    %eax,%r12d
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
js     1232 <main+0xa2>
je     123b <main+0xab>
mov    0x2d96(%rip),%rcx
mov    (%rcx),%edx
lea    0x34(%rsp),%rsi
mov    %eax,%edi
call   1070 <waitpid@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xddf(%rip),%rdi
jmp    1261 <main+0xd1>
lea    0xde8(%rip),%rdi
jmp    1261 <main+0xd1>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%r14d
mov    (%rbx),%esi
lea    0x18(%rsp),%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
test   %eax,%eax
jns    1270 <main+0xe0>
lea    0xdcc(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d39(%rip),%rcx
mov    (%rcx),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,0x14(%rsp)
mov    0x2cfb(%rip),%rax
mov    (%rax),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,0x10(%rsp)
mov    0x2cf5(%rip),%rax
mov    (%rax),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,0xc(%rsp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
mov    %rax,0x28(%rsp)
mov    0x2c98(%rip),%rax
mov    (%rax),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,%ebx
mov    0x2cac(%rip),%rax
mov    (%rax),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,%r13d
mov    0x2cbf(%rip),%rax
mov    (%rax),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,%r15d
mov    0x2c82(%rip),%rax
mov    (%rax),%rdx
add    $0x1,%rdx
mov    %r12d,%edi
mov    %r14d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
mov    %eax,%r10d
sub    $0x8,%rsp
lea    0xcd2(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    0x1c(%rsp),%ecx
mov    0x18(%rsp),%r8d
mov    0x14(%rsp),%r9d
xor    %eax,%eax
push   %r10
push   %r15
push   %r13
push   %rbx
push   0x50(%rsp)
call   1060 <printf@plt>
add    $0x30,%rsp
mov    0x2c14(%rip),%rax
mov    (%rax),%rdx
mov    %r12d,%edi
mov    %r14d,%esi
mov    %ebp,%ecx
mov    %ebp,%r8d
call   1030 <sys_kcmp@plt>
test   %eax,%eax
jne    13c1 <main+0x231>
lea    0xd33(%rip),%rdi
call   1040 <puts@plt>
jmp    13d1 <main+0x241>
lea    0xce0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2bd0(%rip),%rax
mov    (%rax),%rdx
xor    %ebp,%ebp
mov    %r12d,%edi
mov    %r12d,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_kcmp@plt>
test   %eax,%eax
jne    1404 <main+0x274>
lea    0xcf5(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   10a0 <exit@plt>
lea    0xcbf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.kpath = [15 x i8] c"kcmp-test-file\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [18 x i8] c"Can't create file\00"
@.str.1 = [12 x i8] c"fork failed\00"
@.str.2 = [16 x i8] c"Can't open file\00"
@.str.3 = [107 x i8] c"pid1: %6d pid2: %6d FD: %2ld FILES: %2ld VM: %2ld FS: %2ld SIGHAND: %2ld IO: %2ld SYSVSEM: %2ld INV: %2ld\0A\00"
@KCMP_FILE = global i64 0
@KCMP_FILES = global i64 0
@KCMP_VM = global i64 0
@KCMP_FS = global i64 0
@KCMP_SIGHAND = global i64 0
@KCMP_IO = global i64 0
@KCMP_SYSVSEM = global i64 0
@KCMP_TYPES = global i64 0
@.str.4 = [34 x i8] c"FAIL: 0 expected but %d returned\0A\00"
@.str.5 = [30 x i8] c"PASS: 0 returned as expected\0A\00"
@.str.6 = [35 x i8] c"FAIL: 0 expected but %li returned\0A\00"
@P_ALL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [15 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [15 x i8]* %6 to i8*
%15 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
%21 = call i32 @open(i8* %15, i32 %20, i32 420)
store i32 %21, i32* %9
%22 = call i32 (...) @getpid()
store i32 %22, i32* %7
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = call i32 (...) @fork()
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %115, label %38
38: ; preds = %35
%39 = call i32 (...) @getpid()
store i32 %39, i32* %12
%40 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* @O_RDWR
%42 = call i32 @open(i8* %40, i32 %41, i32 420)
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = load i32, i32* %7
%50 = load i32, i32* %12
%51 = load i32, i32* %7
%52 = load i32, i32* %12
%53 = load i64, i64* @KCMP_FILE
%54 = load i32, i32* %9
%55 = load i32, i32* %10
%56 = call i32 @sys_kcmp(i32 %51, i32 %52, i64 %53, i32 %54, i32 %55)
%57 = load i32, i32* %7
%58 = load i32, i32* %12
%59 = load i64, i64* @KCMP_FILES
%60 = call i32 @sys_kcmp(i32 %57, i32 %58, i64 %59, i32 0, i32 0)
%61 = load i32, i32* %7
%62 = load i32, i32* %12
%63 = load i64, i64* @KCMP_VM
%64 = call i32 @sys_kcmp(i32 %61, i32 %62, i64 %63, i32 0, i32 0)
%65 = load i32, i32* %7
%66 = load i32, i32* %12
%67 = load i64, i64* @KCMP_FS
%68 = call i32 @sys_kcmp(i32 %65, i32 %66, i64 %67, i32 0, i32 0)
%69 = load i32, i32* %7
%70 = load i32, i32* %12
%71 = load i64, i64* @KCMP_SIGHAND
%72 = call i32 @sys_kcmp(i32 %69, i32 %70, i64 %71, i32 0, i32 0)
%73 = load i32, i32* %7
%74 = load i32, i32* %12
%75 = load i64, i64* @KCMP_IO
%76 = call i32 @sys_kcmp(i32 %73, i32 %74, i64 %75, i32 0, i32 0)
%77 = load i32, i32* %7
%78 = load i32, i32* %12
%79 = load i64, i64* @KCMP_SYSVSEM
%80 = call i32 @sys_kcmp(i32 %77, i32 %78, i64 %79, i32 0, i32 0)
%81 = load i32, i32* %7
%82 = load i32, i32* %12
%83 = load i64, i64* @KCMP_TYPES
%84 = add nsw i64 %83, 1
%85 = call i32 @sys_kcmp(i32 %81, i32 %82, i64 %84, i32 0, i32 0)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %50, i32 %56, i32 %60, i32 %64, i32 %68, i32 %72, i32 %76, i32 %80, i32 %85)
%87 = load i32, i32* %7
%88 = load i32, i32* %12
%89 = load i64, i64* @KCMP_FILE
%90 = load i32, i32* %9
%91 = load i32, i32* %9
%92 = call i32 @sys_kcmp(i32 %87, i32 %88, i64 %89, i32 %90, i32 %91)
store i32 %92, i32* %13
%93 = load i32, i32* %13
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %48
%96 = load i32, i32* %13
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %96)
store i32 -1, i32* %13
br label %100
98: ; preds = %48
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %100
100: ; preds = %98, %95
%101 = load i32, i32* %7
%102 = load i32, i32* %7
%103 = load i64, i64* @KCMP_VM
%104 = call i32 @sys_kcmp(i32 %101, i32 %102, i64 %103, i32 0, i32 0)
store i32 %104, i32* %13
%105 = load i32, i32* %13
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %100
%108 = load i32, i32* %13
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %108)
store i32 -1, i32* %13
br label %112
110: ; preds = %100
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %112
112: ; preds = %110, %107
%113 = load i32, i32* %13
%114 = call i32 @exit(i32 %113)
unreachable
115: ; preds = %35
%116 = load i32, i32* %8
%117 = load i32, i32* @P_ALL
%118 = call i32 @waitpid(i32 %116, i32* %11, i32 %117)
ret i32 0
}

LLVM IR (-O2):
@__const.main.kpath = [15 x i8] c"kcmp-test-file\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [18 x i8] c"Can't create file\00"
@.str.1 = [12 x i8] c"fork failed\00"
@.str.2 = [16 x i8] c"Can't open file\00"
@.str.3 = [107 x i8] c"pid1: %6d pid2: %6d FD: %2ld FILES: %2ld VM: %2ld FS: %2ld SIGHAND: %2ld IO: %2ld SYSVSEM: %2ld INV: %2ld\0A\00"
@KCMP_FILE = global i64 0
@KCMP_FILES = global i64 0
@KCMP_VM = global i64 0
@KCMP_FS = global i64 0
@KCMP_SIGHAND = global i64 0
@KCMP_IO = global i64 0
@KCMP_SYSVSEM = global i64 0
@KCMP_TYPES = global i64 0
@.str.4 = [34 x i8] c"FAIL: 0 expected but %d returned\0A\00"
@.str.6 = [35 x i8] c"FAIL: 0 expected but %li returned\0A\00"
@P_ALL = global i32 0
@str.7 = [29 x i8] c"PASS: 0 returned as expected\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [15 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %5, i32 %11, i32 420)
%13 = tail call i32 (...) @getpid()
%14 = icmp slt i32 %12, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = tail call i32 (...) @fork()
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = icmp eq i32 %19, 0
br i1 %25, label %26, label %71
26: ; preds = %24
%27 = tail call i32 (...) @getpid()
%28 = load i32, i32* @O_RDWR
%29 = call i32 @open(i8* %5, i32 %28, i32 420)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = load i64, i64* @KCMP_FILE
%36 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %35, i32 %12, i32 %29)
%37 = load i64, i64* @KCMP_FILES
%38 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %37, i32 0, i32 0)
%39 = load i64, i64* @KCMP_VM
%40 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %39, i32 0, i32 0)
%41 = load i64, i64* @KCMP_FS
%42 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %41, i32 0, i32 0)
%43 = load i64, i64* @KCMP_SIGHAND
%44 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %43, i32 0, i32 0)
%45 = load i64, i64* @KCMP_IO
%46 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %45, i32 0, i32 0)
%47 = load i64, i64* @KCMP_SYSVSEM
%48 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %47, i32 0, i32 0)
%49 = load i64, i64* @KCMP_TYPES
%50 = add nsw i64 %49, 1
%51 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %50, i32 0, i32 0)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([107 x i8], [107 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %27, i32 %36, i32 %38, i32 %40, i32 %42, i32 %44, i32 %46, i32 %48, i32 %51)
%53 = load i64, i64* @KCMP_FILE
%54 = tail call i32 @sys_kcmp(i32 %13, i32 %27, i64 %53, i32 %12, i32 %12)
%55 = icmp eq i32 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %34
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %54)
br label %60
58: ; preds = %34
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
br label %60
60: ; preds = %58, %56
%61 = load i64, i64* @KCMP_VM
%62 = tail call i32 @sys_kcmp(i32 %13, i32 %13, i64 %61, i32 0, i32 0)
%63 = icmp eq i32 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %60
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %62)
br label %68
66: ; preds = %60
%67 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
br label %68
68: ; preds = %66, %64
%69 = phi i32 [ -1, %64 ], [ 0, %66 ]
%70 = tail call i32 @exit(i32 %69)
unreachable
71: ; preds = %24
%72 = load i32, i32* @P_ALL
%73 = call i32 @waitpid(i32 %19, i32* %4, i32 %72)
ret i32 0
}