#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ glb_fatal(char *);
int /*<<< orphan*/ glb_free(char *);
scalar_t__ glb_realloc(char *, int);
scalar_t__ isdigit(char);
int /*<<< orphan*/ sscanf(char *, char *, int *);
size_t strlen(char const *);
int break_up_version(char const *version, int *first, int *second, int *third) {
  char c;
  size_t length, i, k, ct = 0, ctb = 0;
  char *vec = NULL;
  int res[3] = {-1, -1, -1};
  if (version == NULL) {
    *third = -1;
    *second = -1;
    *first = -1;
    return 0;
  }
  length = strlen(version);
  for (i = 0; i < length + 1; i++) {
    c = version[i];
    if (isdigit(c)) {
      ct++;
      vec = (char *)glb_realloc(vec, sizeof(char) * (ct + 1));
      vec[ct - 1] = c;
      vec[ct] = '\0';
    } else {
      ctb++;
      if ((ctb > 3) || (vec == NULL)) {
        glb_fatal("Invalid version string");
        exit(1);
      }
      sscanf(vec, "%d", &res[ctb - 1]);
      ct = 0;
    }
  }
  glb_free(vec);
  *first = res[0];
  *second = res[1];
  *third = res[2];
  return 0;
}


x86 assembly (clang, -O0):
<break_up_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0xe59(%rip),%rax
mov    %rax,-0x6c(%rbp)
mov    0xe57(%rip),%eax
mov    %eax,-0x64(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e9 <break_up_version+0x79>
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1322 <break_up_version+0x1b2>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    12f7 <break_up_version+0x187>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     127e <break_up_version+0x10e>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x50(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <glb_realloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x29(%rbp),%dl
mov    -0x60(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x60(%rbp),%rax
mov    -0x50(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12e1 <break_up_version+0x171>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x3,-0x58(%rbp)
ja     12a0 <break_up_version+0x130>
cmpq   $0x0,-0x60(%rbp)
jne    12b6 <break_up_version+0x146>
lea    0xd65(%rip),%rdi
call   1050 <glb_fatal@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rax
sub    $0x1,%rax
lea    -0x6c(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xd4f(%rip),%rsi
call   1060 <sscanf@plt>
movq   $0x0,-0x50(%rbp)
jmp    12e6 <break_up_version+0x176>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11fe <break_up_version+0x8e>
mov    -0x60(%rbp),%rdi
call   1090 <glb_free@plt>
mov    -0x6c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x68(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x64(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<break_up_version>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movl   $0xffffffff,0x8(%rsp)
ff
movq   $0xffffffffffffffff,(%rsp)
ff
test   %rdi,%rdi
je     1252 <break_up_version+0xe2>
mov    %rdi,%rbx
mov    %rsi,0x18(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rcx,0x28(%rsp)
call   1040 <strlen@plt>
cmp    $0xffffffffffffffff,%rax
je     1266 <break_up_version+0xf6>
mov    %rax,%r12
add    $0x1,%r12
xor    %ebp,%ebp
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
xor    %r14d,%r14d
xor    %r15d,%r15d
mov    %rbx,0x30(%rsp)
jmp    120e <break_up_version+0x9e>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%r14),%rbx
lea    0x2(%r14),%esi
mov    %rbp,%rdi
call   1070 <glb_realloc@plt>
mov    %rax,%rbp
mov    %r13b,(%rax,%r14,1)
movb   $0x0,0x1(%rax,%r14,1)
mov    %rbx,%r14
add    $0x1,%r15
cmp    %r15,%r12
mov    0x30(%rsp),%rbx
je     1268 <break_up_version+0xf8>
movzbl (%rbx,%r15,1),%r13d
movsbl %r13b,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    11e0 <break_up_version+0x70>
mov    0x10(%rsp),%rax
lea    0x1(%rax),%rbx
cmp    $0x3,%rbx
ja     12a1 <break_up_version+0x131>
test   %rbp,%rbp
je     12a1 <break_up_version+0x131>
lea    (%rsp,%rax,4),%rdx
mov    %rbp,%rdi
lea    0xdd4(%rip),%rsi
call   1060 <sscanf@plt>
xor    %r14d,%r14d
mov    %rbx,0x10(%rsp)
jmp    1200 <break_up_version+0x90>
movl   $0xffffffff,(%rcx)
movl   $0xffffffff,(%rdx)
movl   $0xffffffff,(%rsi)
jmp    1290 <break_up_version+0x120>
xor    %ebp,%ebp
mov    %rbp,%rdi
call   1090 <glb_free@plt>
mov    (%rsp),%eax
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x4(%rsp),%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x8(%rsp),%eax
mov    0x28(%rsp),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd58(%rip),%rdi
call   1050 <glb_fatal@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.break_up_version.res = [3 x i32] [i32 -1, i32 -1, i32 -1]
@.str = [23 x i8] c"Invalid version string\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @break_up_version(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
%17 = alloca [3 x i32]
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i64 0, i64* %14
store i64 0, i64* %15
store i8* null, i8** %16
%18 = bitcast [3 x i32]* %17 to i8*
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %4
%22 = load i32*, i32** %9
store i32 -1, i32* %22
%23 = load i32*, i32** %8
store i32 -1, i32* %23
%24 = load i32*, i32** %7
store i32 -1, i32* %24
store i32 0, i32* %5
br label %92
25: ; preds = %4
%26 = load i8*, i8** %6
%27 = call i64 @strlen(i8* %26)
store i64 %27, i64* %11
store i64 0, i64* %12
br label %28
28: ; preds = %77, %25
%29 = load i64, i64* %12
%30 = load i64, i64* %11
%31 = add i64 %30, 1
%32 = icmp ult i64 %29, %31
br i1 %32, label %33, label %80
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = load i64, i64* %12
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8, i8* %36
store i8 %37, i8* %10
%38 = load i8, i8* %10
%39 = call i64 @isdigit(i8 signext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %59
41: ; preds = %33
%42 = load i64, i64* %14
%43 = add i64 %42, 1
store i64 %43, i64* %14
%44 = load i8*, i8** %16
%45 = load i64, i64* %14
%46 = add i64 %45, 1
%47 = mul i64 1, %46
%48 = trunc i64 %47 to i32
%49 = call i64 @glb_realloc(i8* %44, i32 %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %16
%51 = load i8, i8* %10
%52 = load i8*, i8** %16
%53 = load i64, i64* %14
%54 = sub i64 %53, 1
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 %51, i8* %55
%56 = load i8*, i8** %16
%57 = load i64, i64* %14
%58 = getelementptr inbounds i8, i8* %56, i64 %57
store i8 0, i8* %58
br label %76
59: ; preds = %33
%60 = load i64, i64* %15
%61 = add i64 %60, 1
store i64 %61, i64* %15
%62 = load i64, i64* %15
%63 = icmp ugt i64 %62, 3
br i1 %63, label %67, label %64
64: ; preds = %59
%65 = load i8*, i8** %16
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64, %59
%68 = call i32 @glb_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %64
%71 = load i8*, i8** %16
%72 = load i64, i64* %15
%73 = sub i64 %72, 1
%74 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 %73
%75 = call i32 @sscanf(i8* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %74)
store i64 0, i64* %14
br label %76
76: ; preds = %70, %41
br label %77
77: ; preds = %76
%78 = load i64, i64* %12
%79 = add i64 %78, 1
store i64 %79, i64* %12
br label %28
80: ; preds = %28
%81 = load i8*, i8** %16
%82 = call i32 @glb_free(i8* %81)
%83 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%84 = load i32, i32* %83
%85 = load i32*, i32** %7
store i32 %84, i32* %85
%86 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 1
%87 = load i32, i32* %86
%88 = load i32*, i32** %8
store i32 %87, i32* %88
%89 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 2
%90 = load i32, i32* %89
%91 = load i32*, i32** %9
store i32 %90, i32* %91
store i32 0, i32* %5
br label %92
92: ; preds = %80, %21
%93 = load i32, i32* %5
ret i32 %93
}

LLVM IR (-O2):
@.str = [23 x i8] c"Invalid version string\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @break_up_version(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [3 x i32]
%6 = bitcast [3 x i32]* %5 to i8*
%7 = icmp eq i8* %0, null
br i1 %7, label %8, label %9
8: ; preds = %4
store i32 -1, i32* %3
store i32 -1, i32* %2
store i32 -1, i32* %1
br label %55
9: ; preds = %4
%10 = tail call i64 @strlen(i8* %0)
%11 = icmp eq i64 %10, -1
br i1 %11, label %46, label %12
12: ; preds = %9, %40
%13 = phi i8* [ %43, %40 ], [ null, %9 ]
%14 = phi i64 [ %42, %40 ], [ 0, %9 ]
%15 = phi i64 [ %41, %40 ], [ 0, %9 ]
%16 = phi i64 [ %44, %40 ], [ 0, %9 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = call i64 @isdigit(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %12
%22 = add i64 %15, 1
%23 = trunc i64 %15 to i32
%24 = add i32 %23, 2
%25 = call i64 @glb_realloc(i8* %13, i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = getelementptr inbounds i8, i8* %26, i64 %15
store i8 %18, i8* %27
%28 = getelementptr inbounds i8, i8* %26, i64 %22
store i8 0, i8* %28
br label %40
29: ; preds = %12
%30 = add i64 %14, 1
%31 = icmp ugt i64 %30, 3
%32 = icmp eq i8* %13, null
%33 = select i1 %31, i1 true, i1 %32
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @glb_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 %14
%39 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %38)
br label %40
40: ; preds = %21, %37
%41 = phi i64 [ %22, %21 ], [ 0, %37 ]
%42 = phi i64 [ %14, %21 ], [ %30, %37 ]
%43 = phi i8* [ %26, %21 ], [ %13, %37 ]
%44 = add nuw i64 %16, 1
%45 = icmp eq i64 %16, %10
br i1 %45, label %46, label %12
46: ; preds = %40, %9
%47 = phi i8* [ null, %9 ], [ %43, %40 ]
%48 = call i32 @glb_free(i8* %47)
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%50 = load i32, i32* %49
store i32 %50, i32* %1
%51 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%52 = load i32, i32* %51
store i32 %52, i32* %2
%53 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%54 = load i32, i32* %53
store i32 %54, i32* %3
br label %55
55: ; preds = %46, %8
ret i32 0
}