#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
scalar_t__ is_version_line(int /*<<< orphan*/ const *, int);
int /*<<< orphan*/ *memchr(int /*<<< orphan*/ const *, char, size_t);
int get_version_line(const uint8_t *in, size_t in_len, const uint8_t **ver,
                     size_t *ver_len, const uint8_t **rest, size_t *rest_len) {
  const uint8_t *cur;
  size_t cur_len;
  cur = in;
  cur_len = in_len;
  while (cur_len > 0) {
    const uint8_t *end = memchr(cur, '\n', cur_len);
    if (end == NULL)
      break;
    end++;
    if (is_version_line(cur, end - cur)) {
      *ver = cur;
      *ver_len = end - cur;
      *rest = end;
      *rest_len = (in + in_len) - end;
      return 0;
    }
    cur_len -= end - cur;
    cur = end;
  }
  *ver = NULL;
  *ver_len = 0;
  *rest = cur;
  *rest_len = in + in_len - cur;
  return 0;
}


x86 assembly (clang, -O0):
<get_version_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jbe    1231 <get_version_line+0x111>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0xa,%esi
call   1030 <memchr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1181 <get_version_line+0x61>
jmp    1231 <get_version_line+0x111>
mov    -0x50(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%esi
call   1040 <is_version_line@plt>
cmp    $0x0,%rax
je     120a <get_version_line+0xea>
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x50(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x50(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x50(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    127a <get_version_line+0x15a>
mov    -0x50(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
mov    -0x48(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1150 <get_version_line+0x30>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_version_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
mov    %rdi,%rbp
test   %rsi,%rsi
je     11a3 <get_version_line+0x83>
mov    %rdx,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    %r8,0x18(%rsp)
mov    %r9,0x20(%rsp)
mov    %r12,%rbx
mov    %rbp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
call   1030 <memchr@plt>
test   %rax,%rax
je     11ae <get_version_line+0x8e>
mov    %rax,%r14
add    $0x4,%r14
mov    %r14,%r13
sub    %r15,%r13
sar    $0x2,%r13
mov    %r15,%rdi
mov    %r13d,%esi
call   1040 <is_version_line@plt>
test   %rax,%rax
jne    11cd <get_version_line+0xad>
mov    %r14,%r15
sub    %r13,%rbx
jne    1160 <get_version_line+0x40>
xor    %r13d,%r13d
jmp    11b4 <get_version_line+0x94>
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    %rbp,%r14
jmp    11e1 <get_version_line+0xc1>
xor    %r13d,%r13d
mov    %r15,%r14
mov    0x20(%rsp),%r9
mov    0x18(%rsp),%r8
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%rdx
xor    %r15d,%r15d
jmp    11e1 <get_version_line+0xc1>
mov    0x20(%rsp),%r9
mov    0x18(%rsp),%r8
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%rdx
mov    %r15,(%rdx)
mov    %r13,(%rcx)
mov    %r14,(%r8)
lea    0x0(,%r12,4),%rax
add    %rbp,%rax
sub    %r14,%rax
sar    $0x2,%rax
mov    %rax,(%r9)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_version_line(i32* %0, i64 %1, i32** %2, i64* %3, i32** %4, i64* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32**
%11 = alloca i64*
%12 = alloca i32**
%13 = alloca i64*
%14 = alloca i32*
%15 = alloca i64
%16 = alloca i32*
store i32* %0, i32** %8
store i64 %1, i64* %9
store i32** %2, i32*** %10
store i64* %3, i64** %11
store i32** %4, i32*** %12
store i64* %5, i64** %13
%17 = load i32*, i32** %8
store i32* %17, i32** %14
%18 = load i64, i64* %9
store i64 %18, i64* %15
br label %19
19: ; preds = %63, %6
%20 = load i64, i64* %15
%21 = icmp ugt i64 %20, 0
br i1 %21, label %22, label %73
22: ; preds = %19
%23 = load i32*, i32** %14
%24 = load i64, i64* %15
%25 = call i32* @memchr(i32* %23, i8 signext 10, i64 %24)
store i32* %25, i32** %16
%26 = load i32*, i32** %16
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %22
br label %73
29: ; preds = %22
%30 = load i32*, i32** %16
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %16
%32 = load i32*, i32** %14
%33 = load i32*, i32** %16
%34 = load i32*, i32** %14
%35 = ptrtoint i32* %33 to i64
%36 = ptrtoint i32* %34 to i64
%37 = sub i64 %35, %36
%38 = sdiv exact i64 %37, 4
%39 = trunc i64 %38 to i32
%40 = call i64 @is_version_line(i32* %32, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %63
42: ; preds = %29
%43 = load i32*, i32** %14
%44 = load i32**, i32*** %10
store i32* %43, i32** %44
%45 = load i32*, i32** %16
%46 = load i32*, i32** %14
%47 = ptrtoint i32* %45 to i64
%48 = ptrtoint i32* %46 to i64
%49 = sub i64 %47, %48
%50 = sdiv exact i64 %49, 4
%51 = load i64*, i64** %11
store i64 %50, i64* %51
%52 = load i32*, i32** %16
%53 = load i32**, i32*** %12
store i32* %52, i32** %53
%54 = load i32*, i32** %8
%55 = load i64, i64* %9
%56 = getelementptr inbounds i32, i32* %54, i64 %55
%57 = load i32*, i32** %16
%58 = ptrtoint i32* %56 to i64
%59 = ptrtoint i32* %57 to i64
%60 = sub i64 %58, %59
%61 = sdiv exact i64 %60, 4
%62 = load i64*, i64** %13
store i64 %61, i64* %62
store i32 0, i32* %7
br label %87
63: ; preds = %29
%64 = load i32*, i32** %16
%65 = load i32*, i32** %14
%66 = ptrtoint i32* %64 to i64
%67 = ptrtoint i32* %65 to i64
%68 = sub i64 %66, %67
%69 = sdiv exact i64 %68, 4
%70 = load i64, i64* %15
%71 = sub i64 %70, %69
store i64 %71, i64* %15
%72 = load i32*, i32** %16
store i32* %72, i32** %14
br label %19
73: ; preds = %28, %19
%74 = load i32**, i32*** %10
store i32* null, i32** %74
%75 = load i64*, i64** %11
store i64 0, i64* %75
%76 = load i32*, i32** %14
%77 = load i32**, i32*** %12
store i32* %76, i32** %77
%78 = load i32*, i32** %8
%79 = load i64, i64* %9
%80 = getelementptr inbounds i32, i32* %78, i64 %79
%81 = load i32*, i32** %14
%82 = ptrtoint i32* %80 to i64
%83 = ptrtoint i32* %81 to i64
%84 = sub i64 %82, %83
%85 = sdiv exact i64 %84, 4
%86 = load i64*, i64** %13
store i64 %85, i64* %86
store i32 0, i32* %7
br label %87
87: ; preds = %73, %42
%88 = load i32, i32* %7
ret i32 %88
}

LLVM IR (-O2):
define i32 @get_version_line(i32* %0, i64 %1, i32** nocapture writeonly %2, i64* nocapture writeonly %3, i32** nocapture writeonly %4, i64* nocapture writeonly %5) {
%7 = icmp eq i64 %1, 0
br i1 %7, label %25, label %10
8: ; preds = %15
%9 = icmp eq i64 %24, 0
br i1 %9, label %25, label %10
10: ; preds = %6, %8
%11 = phi i64 [ %24, %8 ], [ %1, %6 ]
%12 = phi i32* [ %16, %8 ], [ %0, %6 ]
%13 = tail call i32* @memchr(i32* %12, i8 signext 10, i64 %11)
%14 = icmp eq i32* %13, null
br i1 %14, label %25, label %15
15: ; preds = %10
%16 = getelementptr inbounds i32, i32* %13, i64 1
%17 = ptrtoint i32* %16 to i64
%18 = ptrtoint i32* %12 to i64
%19 = sub i64 %17, %18
%20 = ashr exact i64 %19, 2
%21 = trunc i64 %20 to i32
%22 = tail call i64 @is_version_line(i32* %12, i32 %21)
%23 = icmp eq i64 %22, 0
%24 = sub i64 %11, %20
br i1 %23, label %8, label %25
25: ; preds = %10, %8, %15, %6
%26 = phi i32* [ null, %6 ], [ null, %10 ], [ null, %8 ], [ %12, %15 ]
%27 = phi i64 [ 0, %6 ], [ 0, %10 ], [ 0, %8 ], [ %20, %15 ]
%28 = phi i32* [ %0, %6 ], [ %12, %10 ], [ %16, %8 ], [ %16, %15 ]
store i32* %26, i32** %2
store i64 %27, i64* %3
store i32* %28, i32** %4
%29 = getelementptr inbounds i32, i32* %0, i64 %1
%30 = ptrtoint i32* %29 to i64
%31 = ptrtoint i32* %28 to i64
%32 = sub i64 %30, %31
%33 = ashr exact i64 %32, 2
store i64 %33, i64* %5
ret i32 0
}