#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*/ bzero(char *, size_t);
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *get_header_key(char *str) {
  int ind = 0;
  size_t size = strlen(str);
  for (int i = 0; i < strlen(str); ++i) {
    if (str[i] == ':') {
      ind = i;
      break;
    }
  }
  char key[size];
  bzero(key, size);
  strncpy(key, str, (size_t)ind);
  return strdup(key);
}


x86 assembly (clang, -O0):
<get_header_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11b8 <get_header_key+0x78>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    11a5 <get_header_key+0x65>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11b8 <get_header_key+0x78>
jmp    11aa <get_header_key+0x6a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <get_header_key+0x29>
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
call   1050 <bzero@plt>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rdi
call   1060 <strdup@plt>
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_header_key>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1040 <strlen@plt>
movslq %eax,%r14
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    118a <get_header_key+0x4a>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x3a,(%r12,%rbx,1)
je     118c <get_header_key+0x4c>
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1170 <get_header_key+0x30>
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <bzero@plt>
mov    %ebx,%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1060 <strdup@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @get_header_key(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
store i64 %10, i64* %4
store i32 0, i32* %5
br label %11
11: ; preds = %27, %1
%12 = load i32, i32* %5
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 58
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = load i32, i32* %5
store i32 %25, i32* %3
br label %30
26: ; preds = %16
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %24, %11
%31 = load i64, i64* %4
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %6
%33 = alloca i8, i64 %31
store i64 %31, i64* %7
%34 = load i64, i64* %4
%35 = call i32 @bzero(i8* %33, i64 %34)
%36 = load i8*, i8** %2
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = call i32 @strncpy(i8* %33, i8* %36, i64 %38)
%40 = call i8* @strdup(i8* %33)
%41 = load i8*, i8** %6
ret i8* %40
}

LLVM IR (-O2):
define noalias i8* @get_header_key(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %1, %11
%7 = phi i64 [ %12, %11 ], [ 0, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 58
br i1 %10, label %16, label %11
11: ; preds = %6
%12 = add nuw nsw i64 %7, 1
%13 = tail call i32 @strlen(i8* %0)
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %12, %14
br i1 %15, label %6, label %16
16: ; preds = %11, %6, %1
%17 = phi i64 [ 0, %1 ], [ %7, %6 ], [ 0, %11 ]
%18 = alloca i8, i64 %3
%19 = call i32 @bzero(i8* %18, i64 %3)
%20 = and i64 %17, 4294967295
%21 = call i32 @strncpy(i8* %18, i8* %0, i64 %20)
%22 = call i8* @strdup(i8* %18)
ret i8* %22
}