#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 StringComparisonOutputChar(char, char, int);
int StringComparisonOutputInt(int, int, int);
int StringNumComparisonIntLength(char *, int);
int /*<<< orphan*/ free(char *);
int StringNumComparisonInt(char *first2, int length12, char *second2,
                           int length22, int isSmallerOrGreater) {
  int length13 = StringNumComparisonIntLength(first2, length12);
  int length23 = StringNumComparisonIntLength(second2, length22);
  if (length13 == length23) {
    int i1 = -1;
    int gap1 = length12 - length13;
    int i2 = -1;
    int gap2 = length22 - length23;
    while (i1 < length13) {
      i1++;
      char char1 = first2[i1 + gap1];
      i2++;
      char char2 = second2[i2 + gap2];
      if (char1 != char2) {
        free(first2);
        free(second2);
        return StringComparisonOutputChar(char1, char2, isSmallerOrGreater);
      }
    }
  }
  free(first2);
  free(second2);
  return StringComparisonOutputInt(length13, length23, isSmallerOrGreater);
}


x86 assembly (clang, -O0):
<StringNumComparisonInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <StringNumComparisonIntLength@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <StringNumComparisonIntLength@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    1230 <StringNumComparisonInt+0xf0>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    122b <StringNumComparisonInt+0xeb>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x41(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x42(%rbp)
movsbl -0x41(%rbp),%eax
movsbl -0x42(%rbp),%ecx
cmp    %ecx,%eax
je     1226 <StringNumComparisonInt+0xe6>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x41(%rbp),%cl
mov    -0x42(%rbp),%al
mov    -0x28(%rbp),%edx
movsbl %cl,%edi
movsbl %al,%esi
call   1050 <StringComparisonOutputChar@plt>
mov    %eax,-0x4(%rbp)
jmp    1253 <StringNumComparisonInt+0x113>
jmp    11a4 <StringNumComparisonInt+0x64>
jmp    1230 <StringNumComparisonInt+0xf0>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1060 <StringComparisonOutputInt@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StringNumComparisonInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%r13
call   1040 <StringNumComparisonIntLength@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <StringNumComparisonIntLength@plt>
cmp    %eax,%r12d
jne    11e4 <StringNumComparisonInt+0xa4>
sub    %r12d,%r14d
sub    %r12d,%ebp
movslq %ebp,%rdi
movslq %r14d,%rcx
test   %r12d,%r12d
mov    $0xffffffff,%edx
cmovns %r12d,%edx
movslq %edx,%rdx
add    $0x1,%rdx
add    %r13,%rcx
add    %r15,%rdi
xor    %esi,%esi
nopl   0x0(%rax)
cmp    %rsi,%rdx
je     11e4 <StringNumComparisonInt+0xa4>
movzbl (%rcx,%rsi,1),%ebx
movzbl (%rdi,%rsi,1),%ebp
add    $0x1,%rsi
cmp    %bpl,%bl
je     11a0 <StringNumComparisonInt+0x60>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
movsbl %bl,%edi
movsbl %bpl,%esi
mov    0x4(%rsp),%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <StringComparisonOutputChar@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12d,%edi
mov    %ebx,%esi
mov    0x4(%rsp),%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <StringComparisonOutputInt@plt>

LLVM IR (-O0):
define i32 @StringNumComparisonInt(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8
%19 = alloca i8
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 @StringNumComparisonIntLength(i8* %20, i32 %21)
store i32 %22, i32* %12
%23 = load i8*, i8** %9
%24 = load i32, i32* %10
%25 = call i32 @StringNumComparisonIntLength(i8* %23, i32 %24)
store i32 %25, i32* %13
%26 = load i32, i32* %12
%27 = load i32, i32* %13
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %75
29: ; preds = %5
store i32 -1, i32* %14
%30 = load i32, i32* %8
%31 = load i32, i32* %12
%32 = sub nsw i32 %30, %31
store i32 %32, i32* %15
store i32 -1, i32* %16
%33 = load i32, i32* %10
%34 = load i32, i32* %13
%35 = sub nsw i32 %33, %34
store i32 %35, i32* %17
br label %36
36: ; preds = %73, %29
%37 = load i32, i32* %14
%38 = load i32, i32* %12
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %74
40: ; preds = %36
%41 = load i32, i32* %14
%42 = add nsw i32 %41, 1
store i32 %42, i32* %14
%43 = load i8*, i8** %7
%44 = load i32, i32* %14
%45 = load i32, i32* %15
%46 = add nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
%49 = load i8, i8* %48
store i8 %49, i8* %18
%50 = load i32, i32* %16
%51 = add nsw i32 %50, 1
store i32 %51, i32* %16
%52 = load i8*, i8** %9
%53 = load i32, i32* %16
%54 = load i32, i32* %17
%55 = add nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %52, i64 %56
%58 = load i8, i8* %57
store i8 %58, i8* %19
%59 = load i8, i8* %18
%60 = sext i8 %59 to i32
%61 = load i8, i8* %19
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %60, %62
br i1 %63, label %64, label %73
64: ; preds = %40
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
%67 = load i8*, i8** %9
%68 = call i32 @free(i8* %67)
%69 = load i8, i8* %18
%70 = load i8, i8* %19
%71 = load i32, i32* %11
%72 = call i32 @StringComparisonOutputChar(i8 signext %69, i8 signext %70, i32 %71)
store i32 %72, i32* %6
br label %84
73: ; preds = %40
br label %36
74: ; preds = %36
br label %75
75: ; preds = %74, %5
%76 = load i8*, i8** %7
%77 = call i32 @free(i8* %76)
%78 = load i8*, i8** %9
%79 = call i32 @free(i8* %78)
%80 = load i32, i32* %12
%81 = load i32, i32* %13
%82 = load i32, i32* %11
%83 = call i32 @StringComparisonOutputInt(i32 %80, i32 %81, i32 %82)
store i32 %83, i32* %6
br label %84
84: ; preds = %75, %64
%85 = load i32, i32* %6
ret i32 %85
}

LLVM IR (-O2):
define i32 @StringNumComparisonInt(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = tail call i32 @StringNumComparisonIntLength(i8* %0, i32 %1)
%7 = tail call i32 @StringNumComparisonIntLength(i8* %2, i32 %3)
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %32
9: ; preds = %5
%10 = sub i32 %1, %6
%11 = sub i32 %3, %6
%12 = sext i32 %11 to i64
%13 = sext i32 %10 to i64
%14 = call i32 @llvm.smax.i32(i32 %6, i32 -1)
%15 = sext i32 %14 to i64
br label %16
16: ; preds = %19, %9
%17 = phi i64 [ %20, %19 ], [ -1, %9 ]
%18 = icmp eq i64 %17, %15
br i1 %18, label %32, label %19
19: ; preds = %16
%20 = add nsw i64 %17, 1
%21 = add nsw i64 %20, %13
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = add nsw i64 %20, %12
%25 = getelementptr inbounds i8, i8* %2, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %23, %26
br i1 %27, label %16, label %28
28: ; preds = %19
%29 = tail call i32 @free(i8* %0)
%30 = tail call i32 @free(i8* %2)
%31 = tail call i32 @StringComparisonOutputChar(i8 signext %23, i8 signext %26, i32 %4)
br label %36
32: ; preds = %16, %5
%33 = tail call i32 @free(i8* %0)
%34 = tail call i32 @free(i8* %2)
%35 = tail call i32 @StringComparisonOutputInt(i32 %6, i32 %7, i32 %4)
br label %36
36: ; preds = %28, %32
%37 = phi i32 [ %35, %32 ], [ %31, %28 ]
ret i32 %37
}