#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 stringEquals(char firstString[], char secondString[]) {
  int counter = 0;
  while (counter < strlen(firstString) && counter < strlen(secondString)) {
    if (firstString[counter] != secondString[counter]) {
      return 0;
    }
    counter++;
  }
  if (counter == strlen(firstString) && counter == strlen(secondString)) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<stringEquals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1d(%rbp)
jge    1164 <stringEquals+0x54>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1174 <stringEquals+0x64>
jmp    11ae <stringEquals+0x9e>
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     11a0 <stringEquals+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <stringEquals+0xe9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <stringEquals+0x17>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jne    11f2 <stringEquals+0xe2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jne    11f2 <stringEquals+0xe2>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <stringEquals+0xe9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringEquals>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    115d <stringEquals+0x4d>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    115d <stringEquals+0x4d>
movzbl (%r15,%rbx,1),%eax
cmp    (%r14,%rbx,1),%al
jne    117c <stringEquals+0x6c>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1130 <stringEquals+0x20>
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jne    117c <stringEquals+0x6c>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%ebx
je     117e <stringEquals+0x6e>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @stringEquals(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 = %34, %2
%8 = load i32, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = load i32, i32* %6
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %13, %15
br label %17
17: ; preds = %12, %7
%18 = phi i1 [ false, %7 ], [ %16, %12 ]
br i1 %18, label %19, label %37
19: ; preds = %17
%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
store i32 0, i32* %3
br label %49
34: ; preds = %19
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %7
37: ; preds = %17
%38 = load i32, i32* %6
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
%41 = icmp eq i32 %38, %40
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i32, i32* %6
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
%46 = icmp eq i32 %43, %45
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 1, i32* %3
br label %49
48: ; preds = %42, %37
store i32 0, i32* %3
br label %49
49: ; preds = %48, %47, %33
%50 = load i32, i32* %3
ret i32 %50
}

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