#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*/ bcopy(char *, char *, size_t);
char *calloc(int, size_t);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
size_t strlen(char *);
char *strtok(char *, char *);
void parse_http_header_line(char *pieces[], char *line, size_t pieceslen) {
  size_t length = strlen(line);
  char *copy = malloc(length + 1);
  size_t i = 0;
  for (i = 0; i < (length + 1) && line[i] != '\0'; i++) {
    copy[i] = line[i];
  }
  for (; i < (length + 1); i++) {
    copy[i] = '\0';
  }
  char *tok = copy;
  i = 0;
  while ((tok = strtok(tok, " ")) != NULL) {
    size_t len = strlen(tok);
    pieces[i] = calloc(1, len + 1);
    bcopy(tok, pieces[i], len + 1);
    tok = NULL;
    if (i < pieceslen) {
      ++i;
    } else {
      break;
    }
  }
  free(copy);
}


x86 assembly (clang, -O0):
<parse_http_header_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x41(%rbp)
jae    11d1 <parse_http_header_line+0x71>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11e1 <parse_http_header_line+0x81>
jmp    1208 <parse_http_header_line+0xa8>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11a2 <parse_http_header_line+0x42>
jmp    120d <parse_http_header_line+0xad>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    123f <parse_http_header_line+0xdf>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    120d <parse_http_header_line+0xad>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12e9 <parse_http_header_line+0x189>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x40(%rbp),%rdx
add    $0x1,%rdx
call   1070 <bcopy@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12df <parse_http_header_line+0x17f>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    12e4 <parse_http_header_line+0x184>
jmp    12e9 <parse_http_header_line+0x189>
jmp    124f <parse_http_header_line+0xef>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_http_header_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
inc    %rbx
je     11dd <parse_http_header_line+0x6d>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r12,%rax,1),%ecx
test   %cl,%cl
je     11c8 <parse_http_header_line+0x58>
mov    %cl,0x0(%rbp,%rax,1)
add    $0x1,%rax
cmp    %rax,%rbx
jne    11b0 <parse_http_header_line+0x40>
jmp    11dd <parse_http_header_line+0x6d>
sub    %rax,%rbx
jbe    11dd <parse_http_header_line+0x6d>
mov    %rbp,%rdi
add    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
add    $0x1,%r13
xor    %r15d,%r15d
lea    0xe15(%rip),%r12
mov    %rbp,(%rsp)
mov    %rbp,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     1249 <parse_http_header_line+0xd9>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rbp
mov    $0x1,%edi
mov    %rbp,%rsi
call   1060 <calloc@plt>
mov    %rax,(%r14,%r15,8)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1080 <memmove@plt>
add    $0x1,%r15
mov    $0x0,%edi
cmp    %r15,%r13
jne    1200 <parse_http_header_line+0x90>
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @parse_http_header_line(i8** %0, i8* %1, i64 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
%14 = load i64, i64* %7
%15 = add i64 %14, 1
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %8
store i64 0, i64* %9
store i64 0, i64* %9
br label %17
17: ; preds = %39, %3
%18 = load i64, i64* %9
%19 = load i64, i64* %7
%20 = add i64 %19, 1
%21 = icmp ult i64 %18, %20
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i64, i64* %9
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br label %29
29: ; preds = %22, %17
%30 = phi i1 [ false, %17 ], [ %28, %22 ]
br i1 %30, label %31, label %42
31: ; preds = %29
%32 = load i8*, i8** %5
%33 = load i64, i64* %9
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = load i8*, i8** %8
%37 = load i64, i64* %9
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 %35, i8* %38
br label %39
39: ; preds = %31
%40 = load i64, i64* %9
%41 = add i64 %40, 1
store i64 %41, i64* %9
br label %17
42: ; preds = %29
br label %43
43: ; preds = %52, %42
%44 = load i64, i64* %9
%45 = load i64, i64* %7
%46 = add i64 %45, 1
%47 = icmp ult i64 %44, %46
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = load i8*, i8** %8
%50 = load i64, i64* %9
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %48
%53 = load i64, i64* %9
%54 = add i64 %53, 1
store i64 %54, i64* %9
br label %43
55: ; preds = %43
%56 = load i8*, i8** %8
store i8* %56, i8** %10
store i64 0, i64* %9
br label %57
57: ; preds = %85, %55
%58 = load i8*, i8** %10
%59 = call i8* @strtok(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %59, i8** %10
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %86
61: ; preds = %57
%62 = load i8*, i8** %10
%63 = call i64 @strlen(i8* %62)
store i64 %63, i64* %11
%64 = load i64, i64* %11
%65 = add i64 %64, 1
%66 = call i8* @calloc(i32 1, i64 %65)
%67 = load i8**, i8*** %4
%68 = load i64, i64* %9
%69 = getelementptr inbounds i8*, i8** %67, i64 %68
store i8* %66, i8** %69
%70 = load i8*, i8** %10
%71 = load i8**, i8*** %4
%72 = load i64, i64* %9
%73 = getelementptr inbounds i8*, i8** %71, i64 %72
%74 = load i8*, i8** %73
%75 = load i64, i64* %11
%76 = add i64 %75, 1
%77 = call i32 @bcopy(i8* %70, i8* %74, i64 %76)
store i8* null, i8** %10
%78 = load i64, i64* %9
%79 = load i64, i64* %6
%80 = icmp ult i64 %78, %79
br i1 %80, label %81, label %84
81: ; preds = %61
%82 = load i64, i64* %9
%83 = add i64 %82, 1
store i64 %83, i64* %9
br label %85
84: ; preds = %61
br label %86
85: ; preds = %81
br label %57
86: ; preds = %84, %57
%87 = load i8*, i8** %8
%88 = call i32 @free(i8* %87)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @parse_http_header_line(i8** nocapture writeonly %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %4, 1
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i64 %5, 0
br i1 %7, label %22, label %8
8: ; preds = %3, %13
%9 = phi i64 [ %15, %13 ], [ 0, %3 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %6, i64 %9
store i8 %11, i8* %14
%15 = add nuw i64 %9, 1
%16 = icmp eq i64 %9, %4
br i1 %16, label %22, label %8
17: ; preds = %8
%18 = icmp ugt i64 %5, %9
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = getelementptr i8, i8* %6, i64 %9
%21 = sub i64 %5, %9
br label %22
22: ; preds = %13, %3, %19, %17
br label %23
23: ; preds = %22, %28
%24 = phi i8* [ null, %28 ], [ %6, %22 ]
%25 = phi i64 [ %33, %28 ], [ 0, %22 ]
%26 = tail call i8* @strtok(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %35, label %28
28: ; preds = %23
%29 = tail call i64 @strlen(i8* %26)
%30 = add i64 %29, 1
%31 = tail call i8* @calloc(i32 1, i64 %30)
%32 = getelementptr inbounds i8*, i8** %0, i64 %25
store i8* %31, i8** %32
tail call void @llvm.memmove.p0i8.p0i8.i64(i8* align 1 %31, i8* align 1 %26, i64 %30, i1 false)
%33 = add i64 %25, 1
%34 = icmp eq i64 %25, %2
br i1 %34, label %35, label %23
35: ; preds = %28, %23
%36 = tail call i32 @free(i8* %6)
ret void
}