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


x86 assembly (clang, -O0):
<strcmp>:
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    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1152 <strcmp+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <strcmp+0xa4>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ad <strcmp+0x9d>
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     119a <strcmp+0x8a>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <strcmp+0xa4>
jmp    119f <strcmp+0x8f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <strcmp+0x49>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%r15
jne    1177 <strcmp+0x67>
mov    (%r12),%cl
test   %cl,%cl
je     1172 <strcmp+0x62>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%edx
movzbl (%r14,%rax,1),%ebx
cmp    %bl,%cl
jne    1169 <strcmp+0x59>
movzbl 0x1(%r12,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1150 <strcmp+0x40>
xor    %eax,%eax
cmp    %bl,%dl
sete   %al
jmp    1177 <strcmp+0x67>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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