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


x86 assembly (clang, -O0):
<str_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     114e <str_equal+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11db <str_equal+0xcb>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11d4 <str_equal+0xc4>
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     1196 <str_equal+0x86>
jmp    11d4 <str_equal+0xc4>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11c1 <str_equal+0xb1>
movl   $0x1,-0x4(%rbp)
jmp    11db <str_equal+0xcb>
jmp    11c6 <str_equal+0xb6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <str_equal+0x45>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_equal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    %eax,%ebp
jne    1185 <str_equal+0x75>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1185 <str_equal+0x75>
xor    %r14d,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rbp,1),%eax
cmp    (%r15,%rbp,1),%al
jne    1185 <str_equal+0x75>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cmp    %rax,%rbp
je     117f <str_equal+0x6f>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1150 <str_equal+0x40>
jmp    1185 <str_equal+0x75>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @str_equal(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
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = icmp ne i32 %8, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %46
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %42, %13
%15 = load i32, i32* %6
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %45
19: ; preds = %14
%20 = load i8*, i8** %4
%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 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %25, %31
br i1 %32, label %33, label %34
33: ; preds = %19
br label %45
34: ; preds = %19
%35 = load i32, i32* %6
%36 = load i8*, i8** %4
%37 = call i32 @strlen(i8* %36)
%38 = sub nsw i32 %37, 1
%39 = icmp eq i32 %35, %38
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 1, i32* %3
br label %46
41: ; preds = %34
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %14
45: ; preds = %33, %14
store i32 0, i32* %3
br label %46
46: ; preds = %45, %40, %12
%47 = load i32, i32* %3
ret i32 %47
}

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