#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 memcmp(int *, int *, int);
int /*<<< orphan*/ sscanf(char const *, char *, int *, int *, int *);
int cctools_version_cmp(const char *v1, const char *v2) {
  int major1 = 0, minor1 = 0, micro1 = 0;
  int major2 = 0, minor2 = 0, micro2 = 0;
  sscanf(v1, "%d.%d.%d", &major1, &minor1, &micro1);
  sscanf(v2, "%d.%d.%d", &major2, &minor2, &micro2);
  int rc = memcmp(&major1, &major2, sizeof(int));
  if (!rc)
    rc = memcmp(&minor1, &minor2, sizeof(int));
  if (!rc)
    rc = memcmp(&micro1, &micro2, sizeof(int));
  return rc;
}


x86 assembly (clang, -O0):
<cctools_version_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1040 <sscanf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1040 <sscanf@plt>
lea    -0x14(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11c6 <cctools_version_cmp+0xa6>
lea    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11e5 <cctools_version_cmp+0xc5>
lea    -0x1c(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cctools_version_cmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movl   $0x0,0x14(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xe9c(%rip),%r14
lea    0x14(%rsp),%r15
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
lea    0x10(%rsp),%r12
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
jne    11d7 <cctools_version_cmp+0xb7>
lea    0xc(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
jne    11d7 <cctools_version_cmp+0xb7>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d.%d.%d\00"
define i32 @cctools_version_cmp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i8*, i8** %3
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%14 = load i8*, i8** %4
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9, i32* %10)
%16 = call i32 @memcmp(i32* %5, i32* %8, i32 4)
store i32 %16, i32* %11
%17 = load i32, i32* %11
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %2
%20 = call i32 @memcmp(i32* %6, i32* %9, i32 4)
store i32 %20, i32* %11
br label %21
21: ; preds = %19, %2
%22 = load i32, i32* %11
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @memcmp(i32* %7, i32* %10, i32 4)
store i32 %25, i32* %11
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* %11
ret i32 %27
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d.%d.%d\00"
define i32 @cctools_version_cmp(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%14 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%15 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%16 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8)
%17 = call i32 @memcmp(i32* %3, i32* %6, i32 4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = call i32 @memcmp(i32* %4, i32* %7, i32 4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @memcmp(i32* %5, i32* %8, i32 4)
br label %24
24: ; preds = %2, %22, %19
%25 = phi i32 [ %20, %19 ], [ %23, %22 ], [ %17, %2 ]
ret i32 %25
}