#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*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
char *do_mmap(char *, int *, int /*<<< orphan*/ *);
int link(char *, char *);
int /*<<< orphan*/ memcmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int err, fd1, fd2;
  char *p, *q;
  off_t size;
  ssize_t ssz;
  err = link(argv[1], argv[2]);
  assert(!err);
  p = do_mmap(argv[1], &fd1, &size);
  q = do_mmap(argv[2], &fd2, &size);
  assert(!memcmp(p, q, size));
  ssz = write(fd1, "a", 1);
  assert(ssz == 1);
  munmap(q, size);
  system("cat f2");
  assert(!memcmp(p, q, size));
  ssz = write(fd2, "b", 1);
  assert(ssz == 1);
  assert(!memcmp(p, q, size));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <link@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1040 <do_mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1040 <do_mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x18(%rbp),%edi
lea    0xdf1(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1080 <munmap@plt>
lea    0xdc2(%rip),%rdi
call   1050 <system@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x1c(%rbp),%edi
lea    0xd98(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1090 <link@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xc(%rsp),%rsi
lea    0x4(%rsp),%r15
mov    %r15,%rdx
call   1040 <do_mmap@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
call   1040 <do_mmap@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    0xc(%rsp),%edi
lea    0xe16(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1070 <assert@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1080 <munmap@plt>
lea    0xded(%rip),%rdi
call   1050 <system@plt>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    0x8(%rsp),%edi
lea    0xdc8(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1070 <assert@plt>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [7 x i8] c"cat f2\00"
@.str.2 = [2 x i8] c"b\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @link(i8* %15, i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i8* @do_mmap(i8* %27, i32* %7, i32* %11)
store i8* %28, i8** %9
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i8* @do_mmap(i8* %31, i32* %8, i32* %11)
store i8* %32, i8** %10
%33 = load i8*, i8** %9
%34 = load i8*, i8** %10
%35 = load i32, i32* %11
%36 = call i32 @memcmp(i8* %33, i8* %34, i32 %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i32, i32* %7
%42 = call i32 @write(i32 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 %42, i32* %12
%43 = load i32, i32* %12
%44 = icmp eq i32 %43, 1
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i8*, i8** %10
%48 = load i32, i32* %11
%49 = call i32 @munmap(i8* %47, i32 %48)
%50 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%51 = load i8*, i8** %9
%52 = load i8*, i8** %10
%53 = load i32, i32* %11
%54 = call i32 @memcmp(i8* %51, i8* %52, i32 %53)
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load i32, i32* %8
%60 = call i32 @write(i32 %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %60, i32* %12
%61 = load i32, i32* %12
%62 = icmp eq i32 %61, 1
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = load i8*, i8** %9
%66 = load i8*, i8** %10
%67 = load i32, i32* %11
%68 = call i32 @memcmp(i8* %65, i8* %66, i32 %67)
%69 = icmp ne i32 %68, 0
%70 = xor i1 %69, true
%71 = zext i1 %70 to i32
%72 = call i32 @assert(i32 %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [7 x i8] c"cat f2\00"
@.str.2 = [2 x i8] c"b\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @link(i8* %10, i8* %12)
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = load i8*, i8** %9
%18 = call i8* @do_mmap(i8* %17, i32* %3, i32* %5)
%19 = load i8*, i8** %11
%20 = call i8* @do_mmap(i8* %19, i32* %4, i32* %5)
%21 = load i32, i32* %5
%22 = call i32 @memcmp(i8* %18, i8* %20, i32 %21)
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %3
%27 = call i32 @write(i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%28 = icmp eq i32 %27, 1
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* %5
%32 = call i32 @munmap(i8* %20, i32 %31)
%33 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %5
%35 = call i32 @memcmp(i8* %18, i8* %20, i32 %34)
%36 = icmp eq i32 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i32, i32* %4
%40 = call i32 @write(i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%41 = icmp eq i32 %40, 1
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* %5
%45 = call i32 @memcmp(i8* %18, i8* %20, i32 %44)
%46 = icmp eq i32 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
ret i32 0
}