#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*/ errno;
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
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 (%s)\n", ret, strerror(errno));
      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 %d returned (%s)\n", ret, strerror(errno));
      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    $0x90,%rsp
movl   $0x0,-0x14(%rbp)
mov    %edi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    0xe4d(%rip),%rax
mov    %rax,-0x2f(%rbp)
mov    0xe4b(%rip),%eax
mov    %eax,-0x27(%rbp)
mov    0xe45(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe3d(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x2f(%rbp),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
mov    0x2dff(%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    122a <main+0x9a>
lea    0xdf4(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1254 <main+0xc4>
lea    0xddc(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x38(%rbp)
jne    14b9 <main+0x329>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x48(%rbp)
lea    -0x2f(%rbp),%rdi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    12a2 <main+0x112>
lea    0xd9a(%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    0x2ced(%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    0x2cae(%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    0x2ca8(%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    0x2c7a(%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    0x2c4c(%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    0x2c67(%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    0x2c79(%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    0x2c3b(%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    0xc7e(%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    0x2bbf(%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     1439 <main+0x2a9>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x6c(%rbp),%esi
mov    %rax,%rdx
lea    0xc82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4c(%rbp)
jmp    1447 <main+0x2b7>
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    0x2b4c(%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     14a3 <main+0x313>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x70(%rbp),%esi
mov    %rax,%rdx
lea    0xc18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4c(%rbp)
jmp    14b1 <main+0x321>
lea    0xc25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%edi
mov    0x2ad5(%rip),%rax
mov    (%rax),%edx
lea    -0x44(%rbp),%rsi
call   1060 <waitpid@plt>
xor    %eax,%eax
add    $0x90,%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    0x2e02(%rip),%rbx
mov    0x2e23(%rip),%rcx
mov    (%rcx),%esi
or     (%rbx),%esi
mov    %rax,0x18(%rsp)
mov    0x2e0b(%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     1239 <main+0x99>
mov    %eax,%r12d
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
js     1242 <main+0xa2>
je     124b <main+0xab>
mov    0x2d7e(%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    0xdcf(%rip),%rdi
jmp    1271 <main+0xd1>
lea    0xdd8(%rip),%rdi
jmp    1271 <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    1280 <main+0xe0>
lea    0xdbc(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d21(%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    0x2ce3(%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    0x2cdd(%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    0x2caf(%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    0x2c80(%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    0x2c9c(%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    0x2caf(%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    0x2c72(%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    0xcc2(%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    0x2bfc(%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    13d1 <main+0x231>
lea    0xd05(%rip),%rdi
call   1040 <puts@plt>
jmp    13f4 <main+0x254>
mov    %eax,%ebp
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcc0(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2ba5(%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    1427 <main+0x287>
lea    0xcb4(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   10a0 <exit@plt>
mov    %eax,%ebx
mov    0x2b80(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xc6a(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
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 = [39 x i8] c"FAIL: 0 expected but %d returned (%s)\0A\00"
@errno = global i32 0
@.str.5 = [30 x i8] c"PASS: 0 returned as expected\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 %119, 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 %100
95: ; preds = %48
%96 = load i32, i32* %13
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %96, i8* %98)
store i32 -1, i32* %13
br label %102
100: ; preds = %48
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %102
102: ; preds = %100, %95
%103 = load i32, i32* %7
%104 = load i32, i32* %7
%105 = load i64, i64* @KCMP_VM
%106 = call i32 @sys_kcmp(i32 %103, i32 %104, i64 %105, i32 0, i32 0)
store i32 %106, i32* %13
%107 = load i32, i32* %13
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %114
109: ; preds = %102
%110 = load i32, i32* %13
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %110, i8* %112)
store i32 -1, i32* %13
br label %116
114: ; preds = %102
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %116
116: ; preds = %114, %109
%117 = load i32, i32* %13
%118 = call i32 @exit(i32 %117)
unreachable
119: ; preds = %35
%120 = load i32, i32* %8
%121 = load i32, i32* @P_ALL
%122 = call i32 @waitpid(i32 %120, i32* %11, i32 %121)
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 = [39 x i8] c"FAIL: 0 expected but %d returned (%s)\0A\00"
@errno = global i32 0
@P_ALL = global i32 0
@str.6 = [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 %75
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 %60, label %56
56: ; preds = %34
%57 = load i32, i32* @errno
%58 = tail call i8* @strerror(i32 %57)
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %54, i8* %58)
br label %62
60: ; preds = %34
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
br label %62
62: ; preds = %60, %56
%63 = load i64, i64* @KCMP_VM
%64 = tail call i32 @sys_kcmp(i32 %13, i32 %13, i64 %63, i32 0, i32 0)
%65 = icmp eq i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i32, i32* @errno
%68 = tail call i8* @strerror(i32 %67)
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %64, i8* %68)
br label %72
70: ; preds = %62
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
%73 = phi i32 [ -1, %66 ], [ 0, %70 ]
%74 = tail call i32 @exit(i32 %73)
unreachable
75: ; preds = %24
%76 = load i32, i32* @P_ALL
%77 = call i32 @waitpid(i32 %19, i32* %4, i32 %76)
ret i32 0
}