#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 */
scalar_t__ strtoul(char *, char **, int);
void decode_version(char *buf, int *version, int *modification, int *patch) {
  char *endp;
  *version = (int)strtoul(buf, &endp, 10);
  *modification = 0;
  *patch = 0;
  if (endp != buf && *endp == '.') {
    buf = endp + 1;
    *modification = (int)strtoul(buf, &endp, 10);
    if (endp != buf && *endp == '.') {
      buf = endp + 1;
      *patch = (int)strtoul(buf, &buf, 10);
    }
  }
}


x86 assembly (clang, -O0):
<decode_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11e3 <decode_version+0xd3>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11e3 <decode_version+0xd3>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11de <decode_version+0xce>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11de <decode_version+0xce>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11e3 <decode_version+0xd3>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_version>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,(%rbx)
movl   $0x0,(%r15)
movl   $0x0,(%r14)
mov    0x8(%rsp),%rbx
cmp    %r12,%rbx
je     1198 <decode_version+0x88>
cmpb   $0x2e,(%rbx)
jne    1198 <decode_version+0x88>
add    $0x1,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,(%r15)
mov    0x8(%rsp),%rdi
cmp    %rbx,%rdi
je     1198 <decode_version+0x88>
cmpb   $0x2e,(%rdi)
jne    1198 <decode_version+0x88>
add    $0x1,%rdi
mov    %rdi,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @decode_version(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = call i64 @strtoul(i8* %0, i8** %6, i32 10)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, %0
br i1 %11, label %28, label %12
12: ; preds = %4
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 46
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = call i64 @strtoul(i8* %16, i8** %6, i32 10)
%18 = trunc i64 %17 to i32
store i32 %18, i32* %2
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, %16
br i1 %20, label %28, label %21
21: ; preds = %15
%22 = load i8, i8* %19
%23 = icmp eq i8 %22, 46
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %25, i8** %5
%26 = call i64 @strtoul(i8* %25, i8** %5, i32 10)
%27 = trunc i64 %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %15, %21, %24, %12, %4
ret void
}