#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(const void *buf1, const void *buf2, int count) {
  int i;
  for (i = 0; i < count; i++) {
    if (*(unsigned char *)buf1 < *(unsigned char *)buf2)
      return -1;
    if (*(unsigned char *)buf1 > *(unsigned char *)buf2)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<memcmp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1179 <memcmp+0x79>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jge    1144 <memcmp+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <memcmp+0x80>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jle    1166 <memcmp+0x66>
movl   $0x1,-0x4(%rbp)
jmp    1180 <memcmp+0x80>
jmp    116b <memcmp+0x6b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1116 <memcmp+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcmp>:
test   %edx,%edx
jle    1117 <memcmp+0x17>
mov    (%rdi),%al
xor    %ecx,%ecx
xor    %edx,%edx
cmp    (%rsi),%al
setae  %dl
lea    -0x1(%rdx,%rdx,1),%eax
cmove  %ecx,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @memcmp(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %32, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp slt i32 %16, %19
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 -1, i32* %4
br label %36
22: ; preds = %13
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp sgt i32 %25, %28
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 1, i32* %4
br label %36
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %9
35: ; preds = %9
store i32 0, i32* %4
br label %36
36: ; preds = %35, %30, %21
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @memcmp(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %12
5: ; preds = %3
%6 = load i8, i8* %0
%7 = load i8, i8* %1
%8 = icmp ult i8 %6, %7
%9 = icmp eq i8 %6, %7
%10 = select i1 %8, i32 -1, i32 1
%11 = select i1 %9, i32 0, i32 %10
br label %12
12: ; preds = %5, %3
%13 = phi i32 [ 0, %3 ], [ %11, %5 ]
ret i32 %13
}