#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 /*<<< orphan*/ __CPROVER_precondition(int /*<<< orphan*/, char *);
int /*<<< orphan*/ __CPROVER_r_ok(void const *, size_t);
int memcmp(const void *s1, const void *s2, size_t n) {
  int res = 0;
  __CPROVER_precondition(__CPROVER_r_ok(s1, n), "memcmp region 1 readable");
  __CPROVER_precondition(__CPROVER_r_ok(s2, n), "memcpy region 2 readable");
  const unsigned char *sc1 = s1, *sc2 = s2;
  for (; n != 0; n--) {
    res = (*sc1++) - (*sc2++);
    if (res != 0)
      return res;
  }
  return res;
}


x86 assembly (clang, -O0):
<memcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <__CPROVER_r_ok@plt>
mov    %eax,%edi
lea    0xeaf(%rip),%rsi
call   1040 <__CPROVER_precondition@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <__CPROVER_r_ok@plt>
mov    %eax,%edi
lea    0xead(%rip),%rsi
call   1040 <__CPROVER_precondition@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e0 <memcmp+0xc0>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movzbl (%rax),%eax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
movzbl (%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ca <memcmp+0xaa>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e6 <memcmp+0xc6>
jmp    11cf <memcmp+0xaf>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1181 <memcmp+0x61>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcmp>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rsi
call   1030 <__CPROVER_r_ok@plt>
lea    0xec3(%rip),%rsi
mov    %eax,%edi
call   1040 <__CPROVER_precondition@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <__CPROVER_r_ok@plt>
lea    0xec3(%rip),%rsi
mov    %eax,%edi
call   1040 <__CPROVER_precondition@plt>
test   %rbx,%rbx
je     1187 <memcmp+0x67>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r15,%rcx,1),%eax
movzbl (%r14,%rcx,1),%edx
sub    %edx,%eax
jne    1189 <memcmp+0x69>
add    $0x1,%rcx
cmp    %rcx,%rbx
jne    1170 <memcmp+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"memcmp region 1 readable\00"
@.str.1 = [25 x i8] c"memcpy region 2 readable\00"
define i32 @memcmp(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %8
%11 = load i8*, i8** %5
%12 = load i64, i64* %7
%13 = call i32 @__CPROVER_r_ok(i8* %11, i64 %12)
%14 = call i32 @__CPROVER_precondition(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %6
%16 = load i64, i64* %7
%17 = call i32 @__CPROVER_r_ok(i8* %15, i64 %16)
%18 = call i32 @__CPROVER_precondition(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8*, i8** %5
store i8* %19, i8** %9
%20 = load i8*, i8** %6
store i8* %20, i8** %10
br label %21
21: ; preds = %39, %3
%22 = load i64, i64* %7
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %21
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %9
%27 = load i8, i8* %25
%28 = zext i8 %27 to i32
%29 = load i8*, i8** %10
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %10
%31 = load i8, i8* %29
%32 = zext i8 %31 to i32
%33 = sub nsw i32 %28, %32
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = load i32, i32* %8
store i32 %37, i32* %4
br label %44
38: ; preds = %24
br label %39
39: ; preds = %38
%40 = load i64, i64* %7
%41 = add i64 %40, -1
store i64 %41, i64* %7
br label %21
42: ; preds = %21
%43 = load i32, i32* %8
store i32 %43, i32* %4
br label %44
44: ; preds = %42, %36
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [25 x i8] c"memcmp region 1 readable\00"
@.str.1 = [25 x i8] c"memcpy region 2 readable\00"
define i32 @memcmp(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @__CPROVER_r_ok(i8* %0, i64 %2)
%5 = tail call i32 @__CPROVER_precondition(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @__CPROVER_r_ok(i8* %1, i64 %2)
%7 = tail call i32 @__CPROVER_precondition(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %2, 0
br i1 %8, label %24, label %9
9: ; preds = %3, %19
%10 = phi i8* [ %20, %19 ], [ %1, %3 ]
%11 = phi i8* [ %21, %19 ], [ %0, %3 ]
%12 = phi i64 [ %22, %19 ], [ %2, %3 ]
%13 = load i8, i8* %11
%14 = zext i8 %13 to i32
%15 = load i8, i8* %10
%16 = zext i8 %15 to i32
%17 = sub nsw i32 %14, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %9
%20 = getelementptr inbounds i8, i8* %10, i64 1
%21 = getelementptr inbounds i8, i8* %11, i64 1
%22 = add i64 %12, -1
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %9
24: ; preds = %9, %19, %3
%25 = phi i32 [ 0, %3 ], [ 0, %19 ], [ %17, %9 ]
ret i32 %25
}