#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 */
char *strpbrk(char const *, char *);
int strtol(char const *, char **, int);
int version_compare(const char *a, const char *b) {
  char *at, *bt;
  int aval, bval;
  a = strpbrk(a, "0123456789");
  b = strpbrk(b, "0123456789");
  while (a && b) {
    aval = strtol(a, &at, 10);
    bval = strtol(b, &bt, 10);
    if (aval != bval) {
      return bval - aval;
    }
    a = strpbrk(at, "0123456789");
    b = strpbrk(bt, "0123456789");
  }
  if (a) {
    return -1;
  }
  if (b) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<version_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1040 <strpbrk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1040 <strpbrk@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x31(%rbp)
je     1173 <version_compare+0x53>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1183 <version_compare+0x63>
jmp    11f4 <version_compare+0xd4>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     11c7 <version_compare+0xa7>
mov    -0x30(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1229 <version_compare+0x109>
mov    -0x20(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1040 <strpbrk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1040 <strpbrk@plt>
mov    %rax,-0x18(%rbp)
jmp    1158 <version_compare+0x38>
cmpq   $0x0,-0x10(%rbp)
je     120b <version_compare+0xeb>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <version_compare+0x109>
cmpq   $0x0,-0x18(%rbp)
je     1222 <version_compare+0x102>
movl   $0x1,-0x4(%rbp)
jmp    1229 <version_compare+0x109>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<version_compare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0xec8(%rip),%r14
mov    %r14,%rsi
call   1040 <strpbrk@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strpbrk@plt>
mov    %rax,%rbx
test   %rax,%rax
setne  %al
test   %r13,%r13
setne  %cl
je     11d9 <version_compare+0xb9>
test   %rbx,%rbx
je     11d9 <version_compare+0xb9>
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0xe8b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
sub    %ebp,%eax
jne    11e6 <version_compare+0xc6>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
call   1040 <strpbrk@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
call   1040 <strpbrk@plt>
mov    %rax,%rbx
test   %rax,%rax
setne  %al
test   %r13,%r13
setne  %cl
je     11d9 <version_compare+0xb9>
test   %rbx,%rbx
jne    1180 <version_compare+0x60>
movzbl %al,%edx
test   %cl,%cl
mov    $0xffffffff,%eax
cmove  %edx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define i32 @version_compare(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i8* @strpbrk(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @strpbrk(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %5
br label %14
14: ; preds = %34, %2
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br label %20
20: ; preds = %17, %14
%21 = phi i1 [ false, %14 ], [ %19, %17 ]
br i1 %21, label %22, label %39
22: ; preds = %20
%23 = load i8*, i8** %4
%24 = call i32 @strtol(i8* %23, i8** %6, i32 10)
store i32 %24, i32* %8
%25 = load i8*, i8** %5
%26 = call i32 @strtol(i8* %25, i8** %7, i32 10)
store i32 %26, i32* %9
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %22
%31 = load i32, i32* %9
%32 = load i32, i32* %8
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %3
br label %48
34: ; preds = %22
%35 = load i8*, i8** %6
%36 = call i8* @strpbrk(i8* %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %36, i8** %4
%37 = load i8*, i8** %7
%38 = call i8* @strpbrk(i8* %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %38, i8** %5
br label %14
39: ; preds = %20
%40 = load i8*, i8** %4
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 -1, i32* %3
br label %48
43: ; preds = %39
%44 = load i8*, i8** %5
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 1, i32* %3
br label %48
47: ; preds = %43
store i32 0, i32* %3
br label %48
48: ; preds = %47, %46, %42, %30
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define i32 @version_compare(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = tail call i8* @strpbrk(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = tail call i8* @strpbrk(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i8* %7, null
%10 = icmp ne i8* %8, null
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %28
12: ; preds = %2, %20
%13 = phi i8* [ %22, %20 ], [ %7, %2 ]
%14 = phi i8* [ %24, %20 ], [ %8, %2 ]
%15 = call i32 @strtol(i8* %13, i8** %3, i32 10)
%16 = call i32 @strtol(i8* %14, i8** %4, i32 10)
%17 = icmp eq i32 %16, %15
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = sub nsw i32 %16, %15
br label %33
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = tail call i8* @strpbrk(i8* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %4
%24 = tail call i8* @strpbrk(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i8* %22, null
%26 = icmp ne i8* %24, null
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %12, label %28
28: ; preds = %20, %2
%29 = phi i1 [ %9, %2 ], [ %25, %20 ]
%30 = phi i1 [ %10, %2 ], [ %26, %20 ]
%31 = zext i1 %30 to i32
%32 = select i1 %29, i32 -1, i32 %31
br label %33
33: ; preds = %28, %18
%34 = phi i32 [ %19, %18 ], [ %32, %28 ]
ret i32 %34
}