#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 strcmp(char const *, char const *);
int strlen(char const *);
long strtol(char const *, char **, int /*<<< orphan*/);
int sim_cmp_string(const char *s1, const char *s2) {
  long int v1, v2;
  char *ep1, *ep2;
  v1 = strtol(s1 + 1, &ep1, 0);
  v2 = strtol(s2 + 1, &ep2, 0);
  if ((ep1 != s1 + strlen(s1) - 1) || (ep2 != s2 + strlen(s2) - 1))
    return strcmp(s1, s2);
  if (v1 == v2)
    return 0;
  if (v1 < v2)
    return -1;
  return 1;
}


x86 assembly (clang, -O0):
<sim_cmp_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rcx
mov    %eax,%edx
mov    -0x40(%rbp),%rax
movslq %edx,%rdx
add    %rdx,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11da <sim_cmp_string+0xaa>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rcx
mov    %eax,%edx
mov    -0x50(%rbp),%rax
movslq %edx,%rdx
add    %rdx,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
je     11ef <sim_cmp_string+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    122a <sim_cmp_string+0xfa>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1209 <sim_cmp_string+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    122a <sim_cmp_string+0xfa>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    1223 <sim_cmp_string+0xf3>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <sim_cmp_string+0xfa>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sim_cmp_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,%r15
lea    0x1(%r14),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,%r12
mov    0x8(%rsp),%r13
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%r13
jne    119c <sim_cmp_string+0x6c>
mov    (%rsp),%r13
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %r14,%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%r13
je     11b4 <sim_cmp_string+0x84>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <strcmp@plt>
xor    %eax,%eax
cmp    %r12,%r15
je     11c6 <sim_cmp_string+0x96>
setge  %al
movzbl %al,%eax
add    %eax,%eax
add    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @sim_cmp_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = call i64 @strtol(i8* %11, i8** %8, i32 0)
store i64 %12, i64* %6
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i64 @strtol(i8* %14, i8** %9, i32 0)
store i64 %15, i64* %7
%16 = load i8*, i8** %8
%17 = load i8*, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = icmp ne i8* %16, %22
br i1 %23, label %33, label %24
24: ; preds = %2
%25 = load i8*, i8** %9
%26 = load i8*, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 -1
%32 = icmp ne i8* %25, %31
br i1 %32, label %33, label %37
33: ; preds = %24, %2
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 @strcmp(i8* %34, i8* %35)
store i32 %36, i32* %3
br label %48
37: ; preds = %24
%38 = load i64, i64* %6
%39 = load i64, i64* %7
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 0, i32* %3
br label %48
42: ; preds = %37
%43 = load i64, i64* %6
%44 = load i64, i64* %7
%45 = icmp slt i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 -1, i32* %3
br label %48
47: ; preds = %42
store i32 1, i32* %3
br label %48
48: ; preds = %47, %46, %41, %33
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
define i32 @sim_cmp_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = call i64 @strtol(i8* %7, i8** %3, i32 0)
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = call i64 @strtol(i8* %9, i8** %4, i32 0)
%11 = load i8*, i8** %3
%12 = tail call i32 @strlen(i8* %0)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = icmp eq i8* %11, %15
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = tail call i32 @strlen(i8* %1)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = icmp eq i8* %18, %22
br i1 %23, label %26, label %24
24: ; preds = %17, %2
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
br label %31
26: ; preds = %17
%27 = icmp eq i64 %8, %10
br i1 %27, label %31, label %28
28: ; preds = %26
%29 = icmp slt i64 %8, %10
%30 = select i1 %29, i32 -1, i32 1
br label %31
31: ; preds = %28, %26, %24
%32 = phi i32 [ %25, %24 ], [ 0, %26 ], [ %30, %28 ]
ret i32 %32
}