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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ __mp_diag(char *, ...);
int /*<<< orphan*/ allocfile(char *, unsigned long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
long __mp_cmpalloc(char *s, unsigned long n, void *a, size_t l) {
  FILE *f;
  char *p;
  long r;
  int c;
  r = -1;
  if ((f = fopen(allocfile(s, n), "rb")) != NULL) {
    r = 0;
    p = (char *)a;
    while (((c = fgetc(f)) != EOF) && (l != 0)) {
      if ((unsigned char)*p != (unsigned char)c) {
        if (r == 0)
          __mp_diag("allocation %lu ("
                    "0x%016lX"
                    ") differences:\n",
                    n, a);
        __mp_diag("\t"
                  "0x%016lX"
                  "  %02X -> %02X (offset %lu)\n",
                  p, (unsigned char)c, (unsigned char)*p,
                  (unsigned long)(p - (char *)a));
        r++;
      }
      p++;
      l--;
    }
    if (c != EOF) {
      __mp_diag("allocation %lu ("
                "0x%016lX"
                ") has decreased in size\n",
                n, a);
      r++;
    } else if (l != 0) {
      __mp_diag("allocation %lu ("
                "0x%016lX"
                ") has increased in size\n",
                n, a);
      r++;
    }
    if (r != 0)
      __mp_diag("\n");
    fclose(f);
  }
  return r;
}


x86 assembly (clang, -O0):
<__mp_cmpalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0xffffffffffffffff,-0x38(%rbp)
ff
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <allocfile@plt>
mov    %eax,%edi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12fc <__mp_cmpalloc+0x1ac>
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x3c(%rbp)
xor    %eax,%eax
mov    0x2e28(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x3d(%rbp)
je     11d6 <__mp_cmpalloc+0x86>
cmpq   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    11e6 <__mp_cmpalloc+0x96>
jmp    126f <__mp_cmpalloc+0x11f>
mov    -0x30(%rbp),%rax
movzbl (%rax),%eax
mov    -0x3c(%rbp),%ecx
movzbl %cl,%ecx
cmp    %ecx,%eax
je     1252 <__mp_cmpalloc+0x102>
cmpq   $0x0,-0x38(%rbp)
jne    121c <__mp_cmpalloc+0xcc>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <__mp_diag@plt>
mov    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%eax
movzbl %al,%edx
mov    -0x30(%rbp),%rax
movzbl (%rax),%ecx
mov    -0x30(%rbp),%r8
mov    -0x18(%rbp),%rax
sub    %rax,%r8
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1050 <__mp_diag@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11a9 <__mp_cmpalloc+0x59>
mov    -0x3c(%rbp),%eax
mov    0x2d6f(%rip),%rcx
cmp    (%rcx),%eax
je     12a8 <__mp_cmpalloc+0x158>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <__mp_diag@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12da <__mp_cmpalloc+0x18a>
cmpq   $0x0,-0x20(%rbp)
je     12d5 <__mp_cmpalloc+0x185>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <__mp_diag@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12da <__mp_cmpalloc+0x18a>
cmpq   $0x0,-0x38(%rbp)
je     12f3 <__mp_cmpalloc+0x1a3>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1050 <__mp_diag@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mp_cmpalloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,0x8(%rsp)
call   1030 <allocfile@plt>
lea    0xe8b(%rip),%rsi
mov    %eax,%edi
call   1070 <fopen@plt>
test   %rax,%rax
je     1276 <__mp_cmpalloc+0x126>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    %eax,%r15d
mov    0x2e4e(%rip),%r13
test   %rbx,%rbx
setne  %cl
xor    %eax,%eax
mov    %rax,(%rsp)
cmp    0x0(%r13),%r15d
setne  %al
je     1263 <__mp_cmpalloc+0x113>
test   %rbx,%rbx
je     1263 <__mp_cmpalloc+0x113>
add    $0xffffffffffffffff,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
mov    %rax,(%rsp)
mov    %rbx,0x10(%rsp)
nopl   (%rax)
movzbl (%r12,%rbp,1),%eax
cmp    %r15b,%al
je     1239 <__mp_cmpalloc+0xe9>
mov    %r12,%rcx
mov    %r14,%r13
lea    (%r12,%rbp,1),%r14
mov    (%rsp),%rbx
test   %rbx,%rbx
jne    1207 <__mp_cmpalloc+0xb7>
lea    0xe0f(%rip),%rdi
mov    0x8(%rsp),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <__mp_diag@plt>
movzbl (%r14),%eax
movzbl %r15b,%edx
movzbl %al,%ecx
lea    0xe16(%rip),%rdi
mov    %r14,%rsi
mov    %rbp,%r8
xor    %eax,%eax
call   1050 <__mp_diag@plt>
add    $0x1,%rbx
mov    %rbx,(%rsp)
mov    %r13,%r14
mov    0x10(%rsp),%rbx
mov    0x2daf(%rip),%r13
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %eax,%r15d
cmp    %rbp,%rbx
setne  %cl
cmp    0x0(%r13),%eax
setne  %al
je     1263 <__mp_cmpalloc+0x113>
lea    0x1(%rbp),%rdx
cmp    %rbp,%rbx
mov    %rdx,%rbp
jne    11d0 <__mp_cmpalloc+0x80>
test   %al,%al
jne    127f <__mp_cmpalloc+0x12f>
test   %cl,%cl
jne    127f <__mp_cmpalloc+0x12f>
mov    (%rsp),%rbx
test   %rbx,%rbx
jne    12af <__mp_cmpalloc+0x15f>
jmp    12bd <__mp_cmpalloc+0x16d>
mov    $0xffffffffffffffff,%rbx
jmp    12c5 <__mp_cmpalloc+0x175>
lea    0xdcb(%rip),%rcx
lea    0xdf5(%rip),%rdi
test   %al,%al
cmovne %rcx,%rdi
mov    0x8(%rsp),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <__mp_diag@plt>
mov    (%rsp),%rbx
add    $0x1,%rbx
test   %rbx,%rbx
je     12bd <__mp_cmpalloc+0x16d>
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1050 <__mp_diag@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [40 x i8] c"allocation %lu (0x%016lX) differences:\0A\00"
@.str.2 = [38 x i8] c"\090x%016lX %02X -> %02X (offset %lu)\0A\00"
@.str.3 = [49 x i8] c"allocation %lu (0x%016lX) has decreased in size\0A\00"
@.str.4 = [49 x i8] c"allocation %lu (0x%016lX) has increased in size\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i64 @__mp_cmpalloc(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i64 -1, i64* %11
%13 = load i8*, i8** %5
%14 = load i64, i64* %6
%15 = call i32 @allocfile(i8* %13, i64 %14)
%16 = call i32* @fopen(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %9
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %94
18: ; preds = %4
store i64 0, i64* %11
%19 = load i8*, i8** %7
store i8* %19, i8** %10
br label %20
20: ; preds = %61, %18
%21 = load i32*, i32** %9
%22 = call i32 @fgetc(i32* %21)
store i32 %22, i32* %12
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i64, i64* %8
%27 = icmp ne i64 %26, 0
br label %28
28: ; preds = %25, %20
%29 = phi i1 [ false, %20 ], [ %27, %25 ]
br i1 %29, label %30, label %66
30: ; preds = %28
%31 = load i8*, i8** %10
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = load i32, i32* %12
%35 = trunc i32 %34 to i8
%36 = zext i8 %35 to i32
%37 = icmp ne i32 %33, %36
br i1 %37, label %38, label %61
38: ; preds = %30
%39 = load i64, i64* %11
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i64, i64* %6
%43 = load i8*, i8** %7
%44 = call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %42, i8* %43)
br label %45
45: ; preds = %41, %38
%46 = load i8*, i8** %10
%47 = load i32, i32* %12
%48 = trunc i32 %47 to i8
%49 = zext i8 %48 to i32
%50 = load i8*, i8** %10
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = load i8*, i8** %10
%54 = load i8*, i8** %7
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %46, i32 %49, i32 %52, i64 %57)
%59 = load i64, i64* %11
%60 = add nsw i64 %59, 1
store i64 %60, i64* %11
br label %61
61: ; preds = %45, %30
%62 = load i8*, i8** %10
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %10
%64 = load i64, i64* %8
%65 = add i64 %64, -1
store i64 %65, i64* %8
br label %20
66: ; preds = %28
%67 = load i32, i32* %12
%68 = load i32, i32* @EOF
%69 = icmp ne i32 %67, %68
br i1 %69, label %70, label %76
70: ; preds = %66
%71 = load i64, i64* %6
%72 = load i8*, i8** %7
%73 = call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %71, i8* %72)
%74 = load i64, i64* %11
%75 = add nsw i64 %74, 1
store i64 %75, i64* %11
br label %86
76: ; preds = %66
%77 = load i64, i64* %8
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %85
79: ; preds = %76
%80 = load i64, i64* %6
%81 = load i8*, i8** %7
%82 = call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i64 %80, i8* %81)
%83 = load i64, i64* %11
%84 = add nsw i64 %83, 1
store i64 %84, i64* %11
br label %85
85: ; preds = %79, %76
br label %86
86: ; preds = %85, %70
%87 = load i64, i64* %11
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %91
91: ; preds = %89, %86
%92 = load i32*, i32** %9
%93 = call i32 @fclose(i32* %92)
br label %94
94: ; preds = %91, %4
%95 = load i64, i64* %11
ret i64 %95
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [40 x i8] c"allocation %lu (0x%016lX) differences:\0A\00"
@.str.2 = [38 x i8] c"\090x%016lX %02X -> %02X (offset %lu)\0A\00"
@.str.3 = [49 x i8] c"allocation %lu (0x%016lX) has decreased in size\0A\00"
@.str.4 = [49 x i8] c"allocation %lu (0x%016lX) has increased in size\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i64 @__mp_cmpalloc(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = tail call i32 @allocfile(i8* %0, i64 %1)
%6 = tail call i32* @fopen(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %62, label %8
8: ; preds = %4
%9 = tail call i32 @fgetc(i32* %6)
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
%12 = icmp ne i64 %3, 0
%13 = and i1 %11, %12
br i1 %13, label %14, label %46
14: ; preds = %8
%15 = ptrtoint i8* %2 to i64
br label %16
16: ; preds = %14, %37
%17 = phi i32 [ %9, %14 ], [ %41, %37 ]
%18 = phi i64 [ %3, %14 ], [ %40, %37 ]
%19 = phi i64 [ 0, %14 ], [ %38, %37 ]
%20 = phi i8* [ %2, %14 ], [ %39, %37 ]
%21 = load i8, i8* %20
%22 = and i32 %17, 255
%23 = trunc i32 %17 to i8
%24 = icmp eq i8 %21, %23
br i1 %24, label %37, label %25
25: ; preds = %16
%26 = icmp eq i64 %19, 0
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = tail call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %1, i8* %2)
%29 = load i8, i8* %20
br label %30
30: ; preds = %27, %25
%31 = phi i8 [ %29, %27 ], [ %21, %25 ]
%32 = zext i8 %31 to i32
%33 = ptrtoint i8* %20 to i64
%34 = sub i64 %33, %15
%35 = tail call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32 %22, i32 %32, i64 %34)
%36 = add nsw i64 %19, 1
br label %37
37: ; preds = %30, %16
%38 = phi i64 [ %36, %30 ], [ %19, %16 ]
%39 = getelementptr inbounds i8, i8* %20, i64 1
%40 = add i64 %18, -1
%41 = tail call i32 @fgetc(i32* %6)
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
%44 = icmp ne i64 %40, 0
%45 = select i1 %43, i1 %44, i1 false
br i1 %45, label %16, label %46
46: ; preds = %37, %8
%47 = phi i64 [ 0, %8 ], [ %38, %37 ]
%48 = phi i1 [ %11, %8 ], [ %43, %37 ]
%49 = phi i1 [ %12, %8 ], [ %44, %37 ]
%50 = select i1 %48, i1 true, i1 %49
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = select i1 %48, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0)
%53 = tail call i32 (i8*, ...) @__mp_diag(i8* %52, i64 %1, i8* %2)
%54 = add nsw i64 %47, 1
br label %55
55: ; preds = %46, %51
%56 = phi i64 [ %54, %51 ], [ %47, %46 ]
%57 = icmp eq i64 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = tail call i32 (i8*, ...) @__mp_diag(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
%61 = tail call i32 @fclose(i32* %6)
br label %62
62: ; preds = %60, %4
%63 = phi i64 [ %56, %60 ], [ -1, %4 ]
ret i64 %63
}