#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 *__skip_digit(char *);
char *__skip_space(char *);
int atoi(char *);
int /*<<< orphan*/ is_digit(char);
scalar_t__ strncasecmp(char *, char *, int);
int http_parse_version(char *ver, char **end) {
  int minor_ver;
  if (strncasecmp(ver, "HTTP", 4) != 0)
    goto err;
  ver = __skip_space(ver + 4);
  if (*ver != '/')
    goto err;
  ver = __skip_space(ver + 1);
  if (!is_digit(*ver) || atoi(ver) != 1)
    goto err;
  ver = __skip_space(__skip_digit(ver + 1));
  if (*ver != '.')
    goto err;
  ver = __skip_space(ver + 1);
  if (!is_digit(*ver))
    goto err;
  minor_ver = atoi(ver);
  *end = __skip_digit(ver + 1);
  return minor_ver;
err:
  return -1;
}


x86 assembly (clang, -O0):
<http_parse_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
je     1184 <http_parse_version+0x34>
jmp    126e <http_parse_version+0x11e>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1030 <__skip_space@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11aa <http_parse_version+0x5a>
jmp    126e <http_parse_version+0x11e>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <__skip_space@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1060 <is_digit@plt>
cmp    $0x0,%eax
je     11e2 <http_parse_version+0x92>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
cmp    $0x1,%eax
je     11e7 <http_parse_version+0x97>
jmp    126e <http_parse_version+0x11e>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <__skip_digit@plt>
mov    %rax,%rdi
call   1030 <__skip_space@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1215 <http_parse_version+0xc5>
jmp    126e <http_parse_version+0x11e>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <__skip_space@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1060 <is_digit@plt>
cmp    $0x0,%eax
jne    1240 <http_parse_version+0xf0>
jmp    126e <http_parse_version+0x11e>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <__skip_digit@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1275 <http_parse_version+0x125>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_parse_version>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9f(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
jne    11fe <http_parse_version+0xae>
add    $0x4,%rbx
mov    %rbx,%rdi
call   1030 <__skip_space@plt>
cmpb   $0x2f,(%rax)
jne    11fe <http_parse_version+0xae>
add    $0x1,%rax
mov    %rax,%rdi
call   1030 <__skip_space@plt>
mov    %rax,%rbx
movsbl (%rax),%edi
call   1060 <is_digit@plt>
test   %eax,%eax
je     11fe <http_parse_version+0xae>
mov    %rbx,%rdi
call   1070 <atoi@plt>
cmp    $0x1,%eax
jne    11fe <http_parse_version+0xae>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <__skip_digit@plt>
mov    %rax,%rdi
call   1030 <__skip_space@plt>
cmpb   $0x2e,(%rax)
jne    11fe <http_parse_version+0xae>
add    $0x1,%rax
mov    %rax,%rdi
call   1030 <__skip_space@plt>
mov    %rax,%rbx
movsbl (%rax),%edi
call   1060 <is_digit@plt>
test   %eax,%eax
je     11fe <http_parse_version+0xae>
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <__skip_digit@plt>
mov    %rax,(%r14)
mov    %ebp,%eax
jmp    1203 <http_parse_version+0xb3>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HTTP\00"
define i32 @http_parse_version(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = call i64 @strncasecmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %60
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 4
%14 = call i8* @__skip_space(i8* %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 47
br i1 %18, label %19, label %20
19: ; preds = %11
br label %60
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i8* @__skip_space(i8* %22)
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = call i32 @is_digit(i8 signext %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = load i8*, i8** %4
%30 = call i32 @atoi(i8* %29)
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %28, %20
br label %60
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = call i8* @__skip_digit(i8* %35)
%37 = call i8* @__skip_space(i8* %36)
store i8* %37, i8** %4
%38 = load i8*, i8** %4
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 46
br i1 %41, label %42, label %43
42: ; preds = %33
br label %60
43: ; preds = %33
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i8* @__skip_space(i8* %45)
store i8* %46, i8** %4
%47 = load i8*, i8** %4
%48 = load i8, i8* %47
%49 = call i32 @is_digit(i8 signext %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %43
br label %60
52: ; preds = %43
%53 = load i8*, i8** %4
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %6
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = call i8* @__skip_digit(i8* %56)
%58 = load i8**, i8*** %5
store i8* %57, i8** %58
%59 = load i32, i32* %6
store i32 %59, i32* %3
br label %61
60: ; preds = %51, %42, %32, %19, %10
store i32 -1, i32* %3
br label %61
61: ; preds = %60, %52
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [5 x i8] c"HTTP\00"
define i32 @http_parse_version(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %35
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 4
%7 = tail call i8* @__skip_space(i8* %6)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %10, label %35
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = tail call i8* @__skip_space(i8* %11)
%13 = load i8, i8* %12
%14 = tail call i32 @is_digit(i8 signext %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %35, label %16
16: ; preds = %10
%17 = tail call i32 @atoi(i8* %12)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = tail call i8* @__skip_digit(i8* %20)
%22 = tail call i8* @__skip_space(i8* %21)
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 46
br i1 %24, label %25, label %35
25: ; preds = %19
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = tail call i8* @__skip_space(i8* %26)
%28 = load i8, i8* %27
%29 = tail call i32 @is_digit(i8 signext %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %25
%32 = tail call i32 @atoi(i8* %27)
%33 = getelementptr inbounds i8, i8* %27, i64 1
%34 = tail call i8* @__skip_digit(i8* %33)
store i8* %34, i8** %1
br label %35
35: ; preds = %2, %5, %16, %10, %19, %25, %31
%36 = phi i32 [ %32, %31 ], [ -1, %25 ], [ -1, %19 ], [ -1, %10 ], [ -1, %16 ], [ -1, %5 ], [ -1, %2 ]
ret i32 %36
}