#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 strlen(char *);
int compare(char str1[], char str2[]) {
  int i;
  for (i = 0; i < strlen(str1) - 1; i++) {
    if (str1[i] != str2[i]) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1185 <compare+0x75>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1172 <compare+0x62>
movl   $0x0,-0x4(%rbp)
jmp    118c <compare+0x7c>
jmp    1177 <compare+0x67>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <compare+0x17>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbp
call   1030 <strlen@plt>
mov    $0x1,%r14d
cmp    $0x2,%eax
jl     1156 <compare+0x46>
xor    %ebx,%ebx
nop
movzbl 0x0(%rbp,%rbx,1),%eax
cmp    (%r15,%rbx,1),%al
jne    1153 <compare+0x43>
add    $0x1,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbx
jl     1130 <compare+0x20>
jmp    1156 <compare+0x46>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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