#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 string_length(char *);
int string_compare(char *s1, char *s2) {
  int length_s1 = string_length(s1);
  int length_s2 = string_length(s2);
  if (length_s1 != length_s2) {
    return 0;
  }
  while (*s1 != '\0') {
    if (*s1 != *s2) {
      return 0;
    }
    s1++;
    s2++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<string_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <string_length@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <string_length@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1150 <string_compare+0x40>
movl   $0x0,-0x4(%rbp)
jmp    11ab <string_compare+0x9b>
jmp    1155 <string_compare+0x45>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <string_compare+0x94>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1187 <string_compare+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11ab <string_compare+0x9b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <string_compare+0x45>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_compare>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <string_length@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <string_length@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%ebp
jne    1157 <string_compare+0x47>
mov    (%rbx),%cl
mov    $0x1,%eax
test   %cl,%cl
je     1157 <string_compare+0x47>
xor    %edx,%edx
xchg   %ax,%ax
cmp    (%r14,%rdx,1),%cl
jne    1155 <string_compare+0x45>
movzbl 0x1(%rbx,%rdx,1),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    1140 <string_compare+0x30>
jmp    1157 <string_compare+0x47>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @string_compare(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** %4
%9 = call i32 @string_length(i8* %8)
store i32 %9, i32* %6
%10 = load i8*, i8** %5
%11 = call i32 @string_length(i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %37
16: ; preds = %2
br label %17
17: ; preds = %31, %16
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %25, %28
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 0, i32* %3
br label %37
31: ; preds = %22
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
br label %17
36: ; preds = %17
store i32 1, i32* %3
br label %37
37: ; preds = %36, %30, %15
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @string_compare(i8* %0, i8* %1) {
%3 = tail call i32 @string_length(i8* %0)
%4 = tail call i32 @string_length(i8* %1)
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %6, %15
%10 = phi i8 [ %18, %15 ], [ %7, %6 ]
%11 = phi i8* [ %16, %15 ], [ %0, %6 ]
%12 = phi i8* [ %17, %15 ], [ %1, %6 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %10, %13
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = getelementptr inbounds i8, i8* %12, i64 1
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %9
20: ; preds = %9, %15, %6, %2
%21 = phi i32 [ 0, %2 ], [ 1, %6 ], [ 0, %9 ], [ 1, %15 ]
ret i32 %21
}