#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 StrCmp(char *str1, char *str2) {
  int l = 0, i, sum = 0;
  l = (StrLen(str1) > StrLen(str2)) ? StrLen(str1) : StrLen(str2);
  for (i = 0; i < l; i++) {
    sum = sum + *str1 - *str2;
  }
  return sum;
}


x86 assembly (clang, -O0):
<StrCmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <StrLen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <StrLen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jle    1161 <StrCmp+0x51>
mov    -0x8(%rbp),%rdi
call   1030 <StrLen@plt>
mov    %eax,-0x24(%rbp)
jmp    116d <StrCmp+0x5d>
mov    -0x10(%rbp),%rdi
call   1030 <StrLen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ac <StrCmp+0x9c>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117a <StrCmp+0x6a>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrCmp>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <StrLen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <StrLen@plt>
cmp    %eax,%ebp
mov    %r14,%rdi
cmovg  %rbx,%rdi
call   1030 <StrLen@plt>
test   %eax,%eax
jle    1152 <StrCmp+0x42>
movsbl (%rbx),%ecx
movsbl (%r14),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0xffffffff,%eax
imul   %esi,%eax
add    %ecx,%eax
sub    %edx,%eax
jmp    1154 <StrCmp+0x44>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @StrCmp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32 @StrLen(i8* %8)
%10 = load i8*, i8** %4
%11 = call i32 @StrLen(i8* %10)
%12 = icmp sgt i32 %9, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 @StrLen(i8* %14)
br label %19
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 @StrLen(i8* %17)
br label %19
19: ; preds = %16, %13
%20 = phi i32 [ %15, %13 ], [ %18, %16 ]
store i32 %20, i32* %5
store i32 0, i32* %6
br label %21
21: ; preds = %35, %19
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i32, i32* %7
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = add nsw i32 %26, %29
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = sub nsw i32 %30, %33
store i32 %34, i32* %7
br label %35
35: ; preds = %25
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %21
38: ; preds = %21
%39 = load i32, i32* %7
ret i32 %39
}

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