#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 strtol(char const *, char **, int /*<<< orphan*/);
int compare_dotted_version(const char *ver, const char *cmp) {
  int n1, n2;
  while (1) {
    n1 = strtol(ver, (char **)&ver, 0);
    n2 = strtol(cmp, (char **)&cmp, 0);
    if (n1 < n2)
      return -1;
    if (n1 > n2)
      return 1;
    if (*ver == '\0' && *cmp == '\0')
      return 0;
    if (*ver)
      ver++;
    if (*cmp)
      cmp++;
  }
}


x86 assembly (clang, -O0):
<compare_dotted_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    115c <compare_dotted_version+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <compare_dotted_version+0xc7>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1174 <compare_dotted_version+0x64>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <compare_dotted_version+0xc7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a0 <compare_dotted_version+0x90>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a0 <compare_dotted_version+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <compare_dotted_version+0xc7>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b9 <compare_dotted_version+0xa9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d2 <compare_dotted_version+0xc2>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <compare_dotted_version+0x10>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_dotted_version>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %rdi,0x8(%rsp)
mov    %rsi,(%rsp)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    $0xffffffff,%r14d
cmp    %eax,%ebx
jl     11bd <compare_dotted_version+0xad>
lea    0x8(%rsp),%r15
mov    %rsp,%r12
jmp    118f <compare_dotted_version+0x7f>
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rbp
cmpb   $0x0,0x0(%rbp)
je     11ba <compare_dotted_version+0xaa>
add    $0x1,%rbp
mov    %rbp,(%rsp)
mov    %r15,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
cmp    %eax,%ebx
jl     11bd <compare_dotted_version+0xad>
cmp    %eax,%ebx
jg     11b2 <compare_dotted_version+0xa2>
mov    0x8(%rsp),%rdi
cmpb   $0x0,(%rdi)
je     1160 <compare_dotted_version+0x50>
add    $0x1,%rdi
mov    %rdi,0x8(%rsp)
mov    (%rsp),%rbp
cmpb   $0x0,0x0(%rbp)
jne    116a <compare_dotted_version+0x5a>
jmp    1172 <compare_dotted_version+0x62>
mov    $0x1,%r14d
jmp    11bd <compare_dotted_version+0xad>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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