#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*/ set_last_error(char *);
char *strchr(char *, char);
scalar_t__ strempty(char *);
char *strstrip(char *);
bool parse_header(char *str, char **field, char **value) {
  char *p;
  p = strchr(str, ':');
  if (!p) {
    set_last_error("Invalid response header: `:' missing");
    return false;
  }
  *p = '\0';
  *field = strstrip(str);
  if (strempty(*field)) {
    set_last_error("Invalid response header: Field name missing");
    return false;
  }
  *value = strstrip(p + 1);
  if (strempty(*value)) {
    set_last_error("Invalid response header: Value missing");
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<parse_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1189 <parse_header+0x49>
lea    0xe88(%rip),%rdi
call   1040 <set_last_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <parse_header+0xdd>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <strstrip@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strempty@plt>
cmp    $0x0,%rax
je     11d1 <parse_header+0x91>
lea    0xe65(%rip),%rdi
call   1040 <set_last_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <parse_header+0xdd>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strstrip@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strempty@plt>
cmp    $0x0,%rax
je     1216 <parse_header+0xd6>
lea    0xe4c(%rip),%rdi
call   1040 <set_last_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <parse_header+0xdd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_header>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1187 <parse_header+0x47>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1050 <strstrip@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
call   1060 <strempty@plt>
test   %rax,%rax
je     1190 <parse_header+0x50>
lea    0xea0(%rip),%rdi
jmp    11b3 <parse_header+0x73>
lea    0xe72(%rip),%rdi
jmp    11b3 <parse_header+0x73>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <strstrip@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
call   1060 <strempty@plt>
test   %rax,%rax
je     11c6 <parse_header+0x86>
lea    0xe9e(%rip),%rdi
call   1040 <set_last_error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0x1,%eax
jmp    11ba <parse_header+0x7a>

LLVM IR (-O0):
@.str = [37 x i8] c"Invalid response header: `:' missing\00"
@.str.1 = [44 x i8] c"Invalid response header: Field name missing\00"
@.str.2 = [39 x i8] c"Invalid response header: Value missing\00"
define i32 @parse_header(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = load i8*, i8** %5
%10 = call i8* @strchr(i8* %9, i8 signext 58)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = call i32 @set_last_error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %38
15: ; preds = %3
%16 = load i8*, i8** %8
store i8 0, i8* %16
%17 = load i8*, i8** %5
%18 = call i8* @strstrip(i8* %17)
%19 = load i8**, i8*** %6
store i8* %18, i8** %19
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %20
%22 = call i64 @strempty(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 @set_last_error(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %38
26: ; preds = %15
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i8* @strstrip(i8* %28)
%30 = load i8**, i8*** %7
store i8* %29, i8** %30
%31 = load i8**, i8*** %7
%32 = load i8*, i8** %31
%33 = call i64 @strempty(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @set_last_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %38
37: ; preds = %26
store i32 1, i32* %4
br label %38
38: ; preds = %37, %35, %24, %13
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [37 x i8] c"Invalid response header: `:' missing\00"
@.str.1 = [44 x i8] c"Invalid response header: Field name missing\00"
@.str.2 = [39 x i8] c"Invalid response header: Value missing\00"
define i32 @parse_header(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %15, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = tail call i8* @strstrip(i8* %0)
store i8* %7, i8** %1
%8 = tail call i64 @strempty(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = tail call i8* @strstrip(i8* %11)
store i8* %12, i8** %2
%13 = tail call i64 @strempty(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10, %6, %3
%16 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), %10 ]
%17 = tail call i32 @set_last_error(i8* %16)
br label %18
18: ; preds = %15, %10
%19 = phi i32 [ 1, %10 ], [ 0, %15 ]
ret i32 %19
}