#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 memcmp(char const *, char const *, size_t);
size_t strlen(char const *);
int strcmp(const char *str1, const char *str2) {
  size_t len1 = strlen(str1);
  size_t len2 = strlen(str2);
  int cmp_result = memcmp(str1, str2, (len1 < len2) ? len1 : len2);
  if (cmp_result != 0)
    return cmp_result;
  if (len1 > len2)
    return 1;
  else if (len1 < len2)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<strcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1175 <strcmp+0x55>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    117d <strcmp+0x5d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
call   1040 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11a6 <strcmp+0x86>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e6 <strcmp+0xc6>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11c0 <strcmp+0xa0>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <strcmp+0xc6>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11da <strcmp+0xba>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <strcmp+0xc6>
jmp    11df <strcmp+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbx
sbb    %ecx,%ecx
cmp    %rax,%rbx
cmovae %rax,%rbx
mov    $0x1,%ebp
cmovbe %ecx,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcmp@plt>
test   %eax,%eax
cmove  %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @strcmp(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %7
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = load i64, i64* %7
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i64, i64* %6
br label %22
20: ; preds = %2
%21 = load i64, i64* %7
br label %22
22: ; preds = %20, %18
%23 = phi i64 [ %19, %18 ], [ %21, %20 ]
%24 = call i32 @memcmp(i8* %13, i8* %14, i64 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = load i32, i32* %8
store i32 %28, i32* %3
br label %41
29: ; preds = %22
%30 = load i64, i64* %6
%31 = load i64, i64* %7
%32 = icmp ugt i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1, i32* %3
br label %41
34: ; preds = %29
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = icmp ult i64 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 -1, i32* %3
br label %41
39: ; preds = %34
br label %40
40: ; preds = %39
store i32 0, i32* %3
br label %41
41: ; preds = %40, %38, %33, %27
%42 = load i32, i32* %3
ret i32 %42
}

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 ult i64 %3, %4
%6 = select i1 %5, i64 %3, i64 %4
%7 = tail call i32 @memcmp(i8* %0, i8* %1, i64 %6)
%8 = icmp eq i32 %7, 0
%9 = icmp ugt i64 %3, %4
%10 = sext i1 %5 to i32
%11 = select i1 %9, i32 1, i32 %10
%12 = select i1 %8, i32 %11, i32 %7
ret i32 %12
}