#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int pid_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ errno;
int /*<<< orphan*/ execlp(char *, char *, char *, char const *, char const *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ stat(char const *, struct stat *);
int waitpid(int, int *, int /*<<< orphan*/);
void compare(const char *f1, const char *f2) {
  struct stat b1, b2;
  int status;
  pid_t pid, rpid;
  if (stat(f2, &b2) || stat(f1, &b1))
    return;
  if (b1.st_size != b2.st_size)
    return;
  pid = fork();
  if (pid == 0)
    execlp("cmp", "cmp", "-s", f1, f2, NULL);
  else if (pid < 0)
    return;
  do
    rpid = waitpid(pid, &status, 0);
  while (rpid == -1 && errno == EINTR);
  if (rpid != pid)
    status = -1;
  if (status != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
    exit(0);
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jne    11ae <compare+0x3e>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     11b3 <compare+0x43>
jmp    12a8 <compare+0x138>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11c6 <compare+0x56>
jmp    12a8 <compare+0x138>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1202 <compare+0x92>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe17(%rip),%rsi
lea    0xe14(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r9d
mov    %rsi,%rdi
call   1080 <execlp@plt>
jmp    1216 <compare+0xa6>
cmpl   $0x0,-0x28(%rbp)
jge    1211 <compare+0xa1>
jmp    12a8 <compare+0x138>
jmp    1216 <compare+0xa6>
jmp    121b <compare+0xab>
mov    -0x28(%rbp),%edi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x2c(%rbp)
mov    %al,-0x2d(%rbp)
jne    1255 <compare+0xe5>
mov    0x2d9e(%rip),%rax
mov    (%rax),%rax
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    121b <compare+0xab>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1273 <compare+0x103>
movl   $0xffffffff,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     12a8 <compare+0x138>
mov    -0x24(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12a8 <compare+0x138>
mov    -0x24(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
jne    12a8 <compare+0x138>
xor    %edi,%edi
call   1070 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
test   %rax,%rax
jne    123e <compare+0xce>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1030 <stat@plt>
test   %rax,%rax
jne    123e <compare+0xce>
mov    0x10(%rsp),%rax
cmp    0x8(%rsp),%rax
jne    123e <compare+0xce>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11cd <compare+0x5d>
jns    11ec <compare+0x7c>
jmp    123e <compare+0xce>
lea    0xe2c(%rip),%rdi
lea    0xe29(%rip),%rdx
mov    %rdi,%rsi
mov    %r14,%rcx
mov    %rbx,%r8
xor    %r9d,%r9d
call   1080 <execlp@plt>
lea    0x4(%rsp),%r14
mov    0x2de8(%rip),%r15
mov    0x2dd9(%rip),%rbx
nop
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1219 <compare+0xa9>
mov    (%rbx),%rcx
cmp    %rcx,(%r15)
je     1200 <compare+0x90>
cmp    %ebp,%eax
jne    123e <compare+0xce>
mov    0x4(%rsp),%edi
cmp    $0xffffffff,%edi
je     123e <compare+0xce>
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     123e <compare+0xce>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %rax,%rax
je     1249 <compare+0xd9>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [4 x i8] c"cmp\00"
@.str.1 = [3 x i8] c"-s\00"
@errno = global i64 0
@EINTR = global i64 0
define void @compare(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i64 @stat(i8* %10, %struct.stat* %6)
%12 = icmp ne i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i64 @stat(i8* %14, %struct.stat* %5)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %2
br label %69
18: ; preds = %13
%19 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%22 = load i64, i64* %21
%23 = icmp ne i64 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %18
br label %69
25: ; preds = %18
%26 = call i32 (...) @fork()
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = load i8*, i8** %4
%32 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31, i32* null)
br label %38
33: ; preds = %25
%34 = load i32, i32* %8
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
br label %69
37: ; preds = %33
br label %38
38: ; preds = %37, %29
br label %39
39: ; preds = %49, %38
%40 = load i32, i32* %8
%41 = call i32 @waitpid(i32 %40, i32* %7, i32 0)
store i32 %41, i32* %9
br label %42
42: ; preds = %39
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i64, i64* @errno
%47 = load i64, i64* @EINTR
%48 = icmp eq i64 %46, %47
br label %49
49: ; preds = %45, %42
%50 = phi i1 [ false, %42 ], [ %48, %45 ]
br i1 %50, label %39, label %51
51: ; preds = %49
%52 = load i32, i32* %9
%53 = load i32, i32* %8
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %51
store i32 -1, i32* %7
br label %56
56: ; preds = %55, %51
%57 = load i32, i32* %7
%58 = icmp ne i32 %57, -1
br i1 %58, label %59, label %69
59: ; preds = %56
%60 = load i32, i32* %7
%61 = call i64 @WIFEXITED(i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %59
%64 = load i32, i32* %7
%65 = call i64 @WEXITSTATUS(i32 %64)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %17, %24, %36, %63, %59, %56
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [4 x i8] c"cmp\00"
@.str.1 = [3 x i8] c"-s\00"
@errno = global i64 0
@EINTR = global i64 0
define void @compare(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca i32
%6 = bitcast %struct.stat* %3 to i8*
%7 = bitcast %struct.stat* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i64 @stat(i8* %1, %struct.stat* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %49
11: ; preds = %2
%12 = call i64 @stat(i8* %0, %struct.stat* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %49
14: ; preds = %11
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
br i1 %19, label %20, label %49
20: ; preds = %14
%21 = call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i32* null)
br label %27
25: ; preds = %20
%26 = icmp slt i32 %21, 0
br i1 %26, label %49, label %27
27: ; preds = %25, %23
br label %28
28: ; preds = %27, %28
%29 = call i32 @waitpid(i32 %21, i32* %5, i32 0)
%30 = icmp eq i32 %29, -1
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINTR
%33 = icmp eq i64 %31, %32
%34 = select i1 %30, i1 %33, i1 false
br i1 %34, label %28, label %35
35: ; preds = %28
%36 = icmp eq i32 %29, %21
br i1 %36, label %37, label %49
37: ; preds = %35
%38 = load i32, i32* %5
%39 = icmp eq i32 %38, -1
br i1 %39, label %49, label %40
40: ; preds = %37
%41 = call i64 @WIFEXITED(i32 %38)
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %40
%44 = load i32, i32* %5
%45 = call i64 @WEXITSTATUS(i32 %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %35, %37, %40, %43, %25, %14, %2, %11
ret void
}