#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 parse_msgstring(char *, size_t, char **, int /*<<< orphan*/);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ verbose(int, char *, char *, ...);
int parse_hello(char *msgbuf, size_t msglen, char **hello) {
  int ret;
  char *p;
  ret = parse_msgstring(msgbuf, msglen, hello, 0);
  p = strchr(*hello, ' ');
  if (p == NULL) {
    verbose(0, "parse_hello: Missing protocol version '%s'\n", *hello);
    exit(1);
  }
  if (strcmp(p + 1, "0.5")) {
    verbose(0, "parse_hello: Bad protocol version %s\n", p + 1);
    exit(1);
  }
  *p = '\0';
  verbose(1, "parse_hello: hello = %s, version = %s\n", *hello, p + 1);
  return ret;
}


x86 assembly (clang, -O0):
<parse_hello>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1050 <parse_msgstring@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bb <parse_hello+0x6b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
xor    %edi,%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <verbose@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    0xe62(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11fb <parse_hello+0xab>
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
xor    %edi,%edi
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1060 <verbose@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    $0x1,%edi
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <verbose@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_hello>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
xor    %ecx,%ecx
call   1050 <parse_msgstring@plt>
mov    %eax,%r14d
mov    (%rbx),%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11bf <parse_hello+0x6f>
mov    %rax,%rbp
lea    0x1(%rax),%r15
lea    0xea5(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11c8 <parse_hello+0x78>
movb   $0x0,0x0(%rbp)
mov    (%rbx),%rdx
lea    0xeb4(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <verbose@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3a(%rip),%rsi
jmp    11cf <parse_hello+0x7f>
lea    0xe61(%rip),%rsi
xor    %edi,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <verbose@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"parse_hello: Missing protocol version '%s'\0A\00"
@.str.1 = [4 x i8] c"0.5\00"
@.str.2 = [38 x i8] c"parse_hello: Bad protocol version %s\0A\00"
@.str.3 = [39 x i8] c"parse_hello: hello = %s, version = %s\0A\00"
define i32 @parse_hello(i8* %0, i64 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8** %2, i8*** %6
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = load i8**, i8*** %6
%12 = call i32 @parse_msgstring(i8* %9, i64 %10, i8** %11, i32 0)
store i32 %12, i32* %7
%13 = load i8**, i8*** %6
%14 = load i8*, i8** %13
%15 = call i8* @strchr(i8* %14, i8 signext 32)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load i8**, i8*** %6
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, i8*, ...) @verbose(i32 0, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %3
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i32 (i32, i8*, i8*, ...) @verbose(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = load i8*, i8** %8
store i8 0, i8* %34
%35 = load i8**, i8*** %6
%36 = load i8*, i8** %35
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = call i32 (i32, i8*, i8*, ...) @verbose(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* %38)
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
@.str = [44 x i8] c"parse_hello: Missing protocol version '%s'\0A\00"
@.str.1 = [4 x i8] c"0.5\00"
@.str.2 = [38 x i8] c"parse_hello: Bad protocol version %s\0A\00"
@.str.3 = [39 x i8] c"parse_hello: hello = %s, version = %s\0A\00"
define i32 @parse_hello(i8* %0, i64 %1, i8** %2) {
%4 = tail call i32 @parse_msgstring(i8* %0, i64 %1, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 (i32, i8*, i8*, ...) @verbose(i32 0, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = tail call i32 (i32, i8*, i8*, ...) @verbose(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11
store i8 0, i8* %6
%19 = load i8*, i8** %2
%20 = tail call i32 (i32, i8*, i8*, ...) @verbose(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %12)
ret i32 %4
}