#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 atoi(char const *);
int countLeadingDigits(char const *);
int countLeadingNondigits(char const *);
int memcmp(char const *, char const *, int);
int strcmp(char const *, char const *);
int cmpStringsWithEmbeddedNumbers(const char *a, const char *b) {
  for (;;) {
    int aNum = countLeadingDigits(a);
    int bNum = countLeadingDigits(b);
    if (aNum >= 0 && bNum >= 0) {
      int diff = atoi(a) - atoi(b);
      if (diff != 0)
        return diff;
      a += aNum;
      b += bNum;
    }
    int aNonNum = countLeadingNondigits(a);
    int bNonNum = countLeadingNondigits(b);
    if (aNonNum != bNonNum)
      return strcmp(a, b);
    else if (aNonNum == 0)
      return 0;
    else {
      int diff = memcmp(a, b, aNonNum);
      if (diff != 0)
        return diff;
      a += aNonNum;
      b += bNonNum;
    }
  }
}


x86 assembly (clang, -O0):
<cmpStringsWithEmbeddedNumbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <countLeadingDigits@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <countLeadingDigits@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11e2 <cmpStringsWithEmbeddedNumbers+0x92>
cmpl   $0x0,-0x20(%rbp)
jl     11e2 <cmpStringsWithEmbeddedNumbers+0x92>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11c0 <cmpStringsWithEmbeddedNumbers+0x70>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1285 <cmpStringsWithEmbeddedNumbers+0x135>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <countLeadingNondigits@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <countLeadingNondigits@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     121b <cmpStringsWithEmbeddedNumbers+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    1285 <cmpStringsWithEmbeddedNumbers+0x135>
cmpl   $0x0,-0x28(%rbp)
jne    1231 <cmpStringsWithEmbeddedNumbers+0xe1>
movl   $0x0,-0x4(%rbp)
jmp    1285 <cmpStringsWithEmbeddedNumbers+0x135>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <memcmp@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1259 <cmpStringsWithEmbeddedNumbers+0x109>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1285 <cmpStringsWithEmbeddedNumbers+0x135>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1280 <cmpStringsWithEmbeddedNumbers+0x130>
jmp    1160 <cmpStringsWithEmbeddedNumbers+0x10>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmpStringsWithEmbeddedNumbers>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
xchg   %ax,%ax
mov    %r12,%rdi
call   1060 <countLeadingDigits@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <countLeadingDigits@plt>
test   %ebp,%ebp
js     119e <cmpStringsWithEmbeddedNumbers+0x4e>
mov    %eax,%r15d
test   %eax,%eax
js     119e <cmpStringsWithEmbeddedNumbers+0x4e>
mov    %r12,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1070 <atoi@plt>
sub    %eax,%ebx
jne    11ed <cmpStringsWithEmbeddedNumbers+0x9d>
mov    %ebp,%eax
add    %rax,%r12
mov    %r15d,%eax
add    %rax,%r14
mov    %r12,%rdi
call   1030 <countLeadingNondigits@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <countLeadingNondigits@plt>
cmp    %eax,%ebp
jne    11d4 <cmpStringsWithEmbeddedNumbers+0x84>
test   %ebp,%ebp
je     11e7 <cmpStringsWithEmbeddedNumbers+0x97>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
test   %eax,%eax
jne    11eb <cmpStringsWithEmbeddedNumbers+0x9b>
movslq %ebp,%rax
add    %rax,%r12
add    %rax,%r14
jmp    1160 <cmpStringsWithEmbeddedNumbers+0x10>
mov    %r12,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strcmp@plt>
xor    %ebx,%ebx
jmp    11ed <cmpStringsWithEmbeddedNumbers+0x9d>
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @cmpStringsWithEmbeddedNumbers(i8* %0, i8* %1) {
br label %3
3: ; preds = %33, %2
%4 = phi i8* [ %1, %2 ], [ %36, %33 ]
%5 = phi i8* [ %0, %2 ], [ %35, %33 ]
%6 = tail call i32 @countLeadingDigits(i8* %5)
%7 = tail call i32 @countLeadingDigits(i8* %4)
%8 = icmp sgt i32 %6, -1
%9 = icmp sgt i32 %7, -1
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %20
11: ; preds = %3
%12 = tail call i32 @atoi(i8* %5)
%13 = tail call i32 @atoi(i8* %4)
%14 = sub nsw i32 %12, %13
%15 = icmp eq i32 %14, 0
%16 = zext i32 %6 to i64
%17 = getelementptr inbounds i8, i8* %5, i64 %16
%18 = zext i32 %7 to i64
%19 = getelementptr inbounds i8, i8* %4, i64 %18
br i1 %15, label %20, label %37
20: ; preds = %11, %3
%21 = phi i8* [ %19, %11 ], [ %4, %3 ]
%22 = phi i8* [ %17, %11 ], [ %5, %3 ]
%23 = tail call i32 @countLeadingNondigits(i8* %22)
%24 = tail call i32 @countLeadingNondigits(i8* %21)
%25 = icmp eq i32 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(1) %21)
br label %37
28: ; preds = %20
%29 = icmp eq i32 %23, 0
br i1 %29, label %37, label %30
30: ; preds = %28
%31 = tail call i32 @memcmp(i8* %22, i8* %21, i32 %23)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = sext i32 %23 to i64
%35 = getelementptr inbounds i8, i8* %22, i64 %34
%36 = getelementptr inbounds i8, i8* %21, i64 %34
br label %3
37: ; preds = %11, %28, %30, %26
%38 = phi i32 [ %27, %26 ], [ %14, %11 ], [ 0, %28 ], [ %31, %30 ]
ret i32 %38
}