#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*/ fprintf(int /*<<< orphan*/, char *, int, char, char);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
int bufcmp(char *b1, char *b2, int bsize) {
  int i;
  for (i = 0; i < bsize; i++) {
    if (strncmp(&b1[i], &b2[i], 1)) {
      fprintf(stderr, "bufcmp: offset %d: Expected: 0x%x, got 0x%x\n", i, b1[i],
              b2[i]);
      return (-1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<bufcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
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    11c2 <bufcmp+0xa2>
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11af <bufcmp+0x8f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%r8
lea    0xe6a(%rip),%rsi
movsbl %cl,%ecx
movsbl (%rax,%r8,1),%r8d
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <bufcmp+0xa9>
jmp    11b4 <bufcmp+0x94>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113a <bufcmp+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufcmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1160 <bufcmp+0x40>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rdi
lea    (%r14,%rbx,1),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1164 <bufcmp+0x44>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <bufcmp+0x20>
xor    %eax,%eax
jmp    118a <bufcmp+0x6a>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
movsbl (%r15,%rbx,1),%ecx
movsbl (%r14,%rbx,1),%r8d
lea    0xe82(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"bufcmp: offset %d: Expected: 0x%x, got 0x%x\0A\00"
define i32 @bufcmp(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 = %39, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %42
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8*, i8** %6
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = call i64 @strncmp(i8* %17, i8* %21, i32 1)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %13
%25 = load i32, i32* @stderr
%26 = load i32, i32* %8
%27 = load i8*, i8** %5
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %6
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %26, i8 signext %31, i8 signext %36)
store i32 -1, i32* %4
br label %43
38: ; preds = %13
br label %39
39: ; preds = %38
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %9
42: ; preds = %9
store i32 0, i32* %4
br label %43
43: ; preds = %42, %24
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"bufcmp: offset %d: Expected: 0x%x, got 0x%x\0A\00"
define i32 @bufcmp(i8* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %22
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %19
%8 = phi i64 [ 0, %5 ], [ %20, %19 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = getelementptr inbounds i8, i8* %1, i64 %8
%11 = tail call i64 @strncmp(i8* %9, i8* %10, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %7
%14 = trunc i64 %8 to i32
%15 = load i32, i32* @stderr
%16 = load i8, i8* %9
%17 = load i8, i8* %10
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %14, i8 signext %16, i8 signext %17)
br label %22
19: ; preds = %7
%20 = add nuw nsw i64 %8, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %22, label %7
22: ; preds = %19, %3, %13
%23 = phi i32 [ -1, %13 ], [ 0, %3 ], [ 0, %19 ]
ret i32 %23
}