#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*/ fprintf(int /*<<< orphan*/, char *);
int parse_version_digit(char *, int *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strstr(char *, char *);
int parse_version(char *str, int *version_major, int *version_minor,
                  int *version_micro, const char **version_string) {
  char *version;
  int position = 0;
  version = strstr(str, "build_version");
  if (version != NULL)
    version = strchr(version, '"');
  if (version == NULL) {
    fprintf(stderr, "Unable to find build_version string\n");
    return 1;
  }
  version++;
  *strchr(version, ' ') = 0;
  *version_string = version;
  *version_major = parse_version_digit(version, &position);
  *version_minor = parse_version_digit(version, &position);
  *version_micro = parse_version_digit(version, &position);
  return 0;
}


x86 assembly (clang, -O0):
<parse_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1194 <parse_version+0x54>
mov    -0x38(%rbp),%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c0 <parse_version+0x80>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122e <parse_version+0xee>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1030 <parse_version_digit@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1030 <parse_version_digit@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1030 <parse_version_digit@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_version>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r13
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
movl   $0x0,0xc(%rsp)
lea    0xe98(%rip),%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11d3 <parse_version+0x93>
mov    %rax,%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d3 <parse_version+0x93>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    %rbx,0x0(%r13)
lea    0xc(%rsp),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <parse_version_digit@plt>
mov    %eax,(%r12)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <parse_version_digit@plt>
mov    %eax,(%r15)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <parse_version_digit@plt>
mov    %eax,(%r14)
xor    %eax,%eax
jmp    11ed <parse_version+0xad>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"build_version\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Unable to find build_version string\0A\00"
define i32 @parse_version(i8* %0, i32* %1, i32* %2, i32* %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i8** %4, i8*** %11
store i32 0, i32* %13
%14 = load i8*, i8** %7
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %12
%16 = load i8*, i8** %12
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = load i8*, i8** %12
%20 = call i8* @strchr(i8* %19, i8 signext 34)
store i8* %20, i8** %12
br label %21
21: ; preds = %18, %5
%22 = load i8*, i8** %12
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %6
br label %43
27: ; preds = %21
%28 = load i8*, i8** %12
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %12
%30 = load i8*, i8** %12
%31 = call i8* @strchr(i8* %30, i8 signext 32)
store i8 0, i8* %31
%32 = load i8*, i8** %12
%33 = load i8**, i8*** %11
store i8* %32, i8** %33
%34 = load i8*, i8** %12
%35 = call i32 @parse_version_digit(i8* %34, i32* %13)
%36 = load i32*, i32** %8
store i32 %35, i32* %36
%37 = load i8*, i8** %12
%38 = call i32 @parse_version_digit(i8* %37, i32* %13)
%39 = load i32*, i32** %9
store i32 %38, i32* %39
%40 = load i8*, i8** %12
%41 = call i32 @parse_version_digit(i8* %40, i32* %13)
%42 = load i32*, i32** %10
store i32 %41, i32* %42
store i32 0, i32* %6
br label %43
43: ; preds = %27, %24
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
@.str = [14 x i8] c"build_version\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Unable to find build_version string\0A\00"
define i32 @parse_version(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i8** nocapture writeonly %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%8 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = tail call i8* @strchr(i8* %8, i8 signext 34)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %5, %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %22
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %11, i64 1
%18 = tail call i8* @strchr(i8* %17, i8 signext 32)
store i8 0, i8* %18
store i8* %17, i8** %4
%19 = call i32 @parse_version_digit(i8* %17, i32* %6)
store i32 %19, i32* %1
%20 = call i32 @parse_version_digit(i8* %17, i32* %6)
store i32 %20, i32* %2
%21 = call i32 @parse_version_digit(i8* %17, i32* %6)
store i32 %21, i32* %3
br label %22
22: ; preds = %16, %13
%23 = phi i32 [ 1, %13 ], [ 0, %16 ]
ret i32 %23
}