#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 strlength(char const *);
int charcmp(const char *buf, const char *match) {
  int len, i;
  len = strlength(match);
  for (i = 0; i < len; ++i)
    if (buf[i] != match[i])
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<charcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlength@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    117e <charcmp+0x6e>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     116b <charcmp+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1185 <charcmp+0x75>
jmp    1170 <charcmp+0x60>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1133 <charcmp+0x23>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charcmp>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlength@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jle    1158 <charcmp+0x48>
mov    %ecx,%ecx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r14,%rdx,1),%ebx
cmp    (%r15,%rdx,1),%bl
jne    1156 <charcmp+0x46>
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1140 <charcmp+0x30>
jmp    1158 <charcmp+0x48>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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