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


x86 assembly (clang, -O0):
<str_cmp>:
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
cmp    %ecx,%eax
jge    11b3 <str_cmp+0xa3>
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
jge    116f <str_cmp+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <str_cmp+0xaa>
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
jle    119b <str_cmp+0x8b>
movl   $0x1,-0x4(%rbp)
jmp    11ba <str_cmp+0xaa>
jmp    11a0 <str_cmp+0x90>
jmp    11a5 <str_cmp+0x95>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <str_cmp+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cmp>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1153 <str_cmp+0x43>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
movzbl (%r14,%rbx,1),%ecx
cmp    %cl,%al
jl     1157 <str_cmp+0x47>
jg     115e <str_cmp+0x4e>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1130 <str_cmp+0x20>
xor    %eax,%eax
jmp    1163 <str_cmp+0x53>
mov    $0xffffffff,%eax
jmp    1163 <str_cmp+0x53>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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