#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 */
int memcmp(void const *, void const *, size_t);
size_t objp_to_size(void *);
int ordering_err_2();
int compare_mem(void *context, const void *check, const void *baseline) {
  size_t n;
  if (!check || !baseline)
    return ordering_err_2();
  n = objp_to_size(context);
  if (n <= 0)
    return (
        ((((((0))) !=
           (((int)-(((int)0x37ED)
                    << (8 * (((!!(((!!(sizeof(int))) * ((sizeof(int)) - 1)))) *
                              ((((!!(sizeof(int))) * ((sizeof(int)) - 1))) -
                               1)))))))) &&
          ((((0))) !=
           (((int)-(((int)0x37EE)
                    << (8 * (((!!(((!!(sizeof(int))) * ((sizeof(int)) - 1)))) *
                              ((((!!(sizeof(int))) * ((sizeof(int)) - 1))) -
                               1))))))))))
            ? ((0))
            : (((((((0)))) <= ((0)))
                    ? ((((((0)))) < ((0)))
                           ? (((((int)-(((int)0x37EF)
                                        << (8 * (((!!(((!!(sizeof(int))) *
                                                       ((sizeof(int)) - 1)))) *
                                                  ((((!!(sizeof(int))) *
                                                     ((sizeof(int)) - 1))) -
                                                   1)))))))))
                           : (((0))))
                    : (((((int)-(((int)-(((int)0x37EF)
                                         << (8 * (((!!(((!!(sizeof(int))) *
                                                        ((sizeof(int)) - 1)))) *
                                                   ((((!!(sizeof(int))) *
                                                      ((sizeof(int)) - 1))) -
                                                    1))))))))))))));
  return (
      (((((memcmp(check, baseline, n))) !=
         (((int)-(((int)0x37ED)
                  << (8 * (((!!(((!!(sizeof(int))) * ((sizeof(int)) - 1)))) *
                            ((((!!(sizeof(int))) * ((sizeof(int)) - 1))) -
                             1)))))))) &&
        (((memcmp(check, baseline, n))) !=
         (((int)-(((int)0x37EE)
                  << (8 * (((!!(((!!(sizeof(int))) * ((sizeof(int)) - 1)))) *
                            ((((!!(sizeof(int))) * ((sizeof(int)) - 1))) -
                             1))))))))))
          ? (memcmp(check, baseline, n))
          : ((((((memcmp(check, baseline, n)))) <= ((0)))
                  ? (((((memcmp(check, baseline, n)))) < ((0)))
                         ? (((((int)-(((int)0x37EF)
                                      << (8 * (((!!(((!!(sizeof(int))) *
                                                     ((sizeof(int)) - 1)))) *
                                                ((((!!(sizeof(int))) *
                                                   ((sizeof(int)) - 1))) -
                                                 1)))))))))
                         : (((0))))
                  : (((((int)-(((int)-(
                        ((int)0x37EF)
                        << (8 *
                            (((!!(((!!(sizeof(int))) * ((sizeof(int)) - 1)))) *
                              ((((!!(sizeof(int))) * ((sizeof(int)) - 1))) -
                               1))))))))))))));
}


x86 assembly (clang, -O0):
<compare_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     115a <compare_mem+0x2a>
cmpq   $0x0,-0x20(%rbp)
jne    1169 <compare_mem+0x39>
mov    $0x0,%al
call   1040 <ordering_err_2@plt>
mov    %eax,-0x4(%rbp)
jmp    1239 <compare_mem+0x109>
mov    -0x10(%rbp),%rdi
call   1050 <objp_to_size@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
ja     118d <compare_mem+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1239 <compare_mem+0x109>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcmp@plt>
cmp    $0xc8130000,%eax
je     11de <compare_mem+0xae>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcmp@plt>
cmp    $0xc8120000,%eax
je     11de <compare_mem+0xae>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
jmp    1233 <compare_mem+0x103>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jg     1220 <compare_mem+0xf0>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcmp@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0xc8110000,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x30(%rbp)
jmp    122d <compare_mem+0xfd>
mov    $0x37ef0000,%eax
mov    %eax,-0x30(%rbp)
jmp    122d <compare_mem+0xfd>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_mem>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1173 <compare_mem+0x43>
mov    %rdx,%r14
test   %rdx,%rdx
je     1173 <compare_mem+0x43>
mov    %rsi,%rbx
call   1050 <objp_to_size@plt>
test   %rax,%rax
je     1181 <compare_mem+0x51>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <memcmp@plt>
mov    %eax,%ecx
or     $0x10000,%ecx
cmp    $0xc8130000,%ecx
jne    1183 <compare_mem+0x53>
mov    $0xc8110000,%eax
jmp    1183 <compare_mem+0x53>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <ordering_err_2@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @compare_mem(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11, %3
%15 = call i32 (...) @ordering_err_2()
store i32 %15, i32* %4
br label %58
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = call i64 @objp_to_size(i8* %17)
store i64 %18, i64* %8
%19 = load i64, i64* %8
%20 = icmp ule i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 0, i32* %4
br label %58
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = load i64, i64* %8
%26 = call i32 @memcmp(i8* %23, i8* %24, i64 %25)
%27 = icmp ne i32 %26, -938278912
br i1 %27, label %28, label %39
28: ; preds = %22
%29 = load i8*, i8** %6
%30 = load i8*, i8** %7
%31 = load i64, i64* %8
%32 = call i32 @memcmp(i8* %29, i8* %30, i64 %31)
%33 = icmp ne i32 %32, -938344448
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = load i64, i64* %8
%38 = call i32 @memcmp(i8* %35, i8* %36, i64 %37)
br label %56
39: ; preds = %28, %22
%40 = load i8*, i8** %6
%41 = load i8*, i8** %7
%42 = load i64, i64* %8
%43 = call i32 @memcmp(i8* %40, i8* %41, i64 %42)
%44 = icmp sle i32 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %39
%46 = load i8*, i8** %6
%47 = load i8*, i8** %7
%48 = load i64, i64* %8
%49 = call i32 @memcmp(i8* %46, i8* %47, i64 %48)
%50 = icmp slt i32 %49, 0
%51 = zext i1 %50 to i64
%52 = select i1 %50, i32 -938409984, i32 0
br label %54
53: ; preds = %39
br label %54
54: ; preds = %53, %45
%55 = phi i32 [ %52, %45 ], [ 938409984, %53 ]
br label %56
56: ; preds = %54, %34
%57 = phi i32 [ %38, %34 ], [ %55, %54 ]
store i32 %57, i32* %4
br label %58
58: ; preds = %56, %21, %14
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
define i32 @compare_mem(i8* %0, i8* %1, i8* %2) {
%4 = icmp ne i8* %1, null
%5 = icmp ne i8* %2, null
%6 = and i1 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 (...) @ordering_err_2()
br label %15
9: ; preds = %3
%10 = tail call i64 @objp_to_size(i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @memcmp(i8* %1, i8* %2, i64 %10)
switch i32 %13, label %15 [
i32 -938278912, label %14
i32 -938344448, label %14
]
14: ; preds = %12, %12
br label %15
15: ; preds = %14, %12, %9, %7
%16 = phi i32 [ %8, %7 ], [ 0, %9 ], [ -938409984, %14 ], [ %13, %12 ]
ret i32 %16
}