#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*/ assert(void *);
char memory_compare(void *p_comparand_a, void *p_comparand_b, size_t size) {
  assert(size);
  assert(p_comparand_a);
  assert(p_comparand_b);
  char result = 1;
  unsigned char *p_in_a = (unsigned char *)p_comparand_a;
  unsigned char *p_in_b = (unsigned char *)p_comparand_b;
  size_t curr_idx = 0;
  for (; curr_idx < size; ++curr_idx)
    if (p_in_a[curr_idx] != p_in_b[curr_idx]) {
      result = 0;
      break;
    }
  return result;
}


x86 assembly (clang, -O0):
<memory_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
movb   $0x1,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a8 <memory_compare+0x98>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1192 <memory_compare+0x82>
movb   $0x0,-0x19(%rbp)
jmp    11a8 <memory_compare+0x98>
jmp    1197 <memory_compare+0x87>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    115b <memory_compare+0x4b>
movsbl -0x19(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_compare>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <assert@plt>
mov    %r15,%rdi
call   1030 <assert@plt>
mov    %r14,%rdi
call   1030 <assert@plt>
mov    $0x1,%al
test   %rbx,%rbx
je     1158 <memory_compare+0x48>
xor    %ecx,%ecx
nop
movzbl (%r15,%rcx,1),%edx
cmp    (%r14,%rcx,1),%dl
jne    1156 <memory_compare+0x46>
add    $0x1,%rcx
cmp    %rcx,%rbx
jne    1140 <memory_compare+0x30>
jmp    1158 <memory_compare+0x48>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define signext i8 @memory_compare(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = load i64, i64* %6
%12 = inttoptr i64 %11 to i8*
%13 = call i32 @assert(i8* %12)
%14 = load i8*, i8** %4
%15 = call i32 @assert(i8* %14)
%16 = load i8*, i8** %5
%17 = call i32 @assert(i8* %16)
store i8 1, i8* %7
%18 = load i8*, i8** %4
store i8* %18, i8** %8
%19 = load i8*, i8** %5
store i8* %19, i8** %9
store i64 0, i64* %10
br label %20
20: ; preds = %38, %3
%21 = load i64, i64* %10
%22 = load i64, i64* %6
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %41
24: ; preds = %20
%25 = load i8*, i8** %8
%26 = load i64, i64* %10
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = load i8*, i8** %9
%31 = load i64, i64* %10
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = icmp ne i32 %29, %34
br i1 %35, label %36, label %37
36: ; preds = %24
store i8 0, i8* %7
br label %41
37: ; preds = %24
br label %38
38: ; preds = %37
%39 = load i64, i64* %10
%40 = add i64 %39, 1
store i64 %40, i64* %10
br label %20
41: ; preds = %36, %20
%42 = load i8, i8* %7
ret i8 %42
}

LLVM IR (-O2):
define signext i8 @memory_compare(i8* %0, i8* %1, i64 %2) {
%4 = inttoptr i64 %2 to i8*
%5 = tail call i32 @assert(i8* %4)
%6 = tail call i32 @assert(i8* %0)
%7 = tail call i32 @assert(i8* %1)
%8 = icmp eq i64 %2, 0
br i1 %8, label %19, label %11
9: ; preds = %11
%10 = icmp eq i64 %18, %2
br i1 %10, label %19, label %11
11: ; preds = %3, %9
%12 = phi i64 [ %18, %9 ], [ 0, %3 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %1, i64 %12
%16 = load i8, i8* %15
%17 = icmp eq i8 %14, %16
%18 = add nuw i64 %12, 1
br i1 %17, label %9, label %19
19: ; preds = %9, %11, %3
%20 = phi i8 [ 1, %3 ], [ 0, %11 ], [ 1, %9 ]
ret i8 %20
}