#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ strcasecmp(char *, char *);
char *strchr(char *, char);
char *strdup(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int header_name_match(char *header, char *tick, int do_tick) {
  char *hname;
  char *lcopy;
  char *p;
  char *q;
  int rc = -1;
  char *hcolon = strchr(header, ':');
  if (hcolon == NULL)
    return rc;
  hname = malloc((hcolon - header) + 1);
  if (hname == NULL)
    return -100;
  memset(hname, 0, (hcolon - header) + 1);
  strncpy(hname, header, (hcolon - header));
  lcopy = strdup(tick);
  if (lcopy == NULL) {
    free(hname);
    return -100;
  }
  p = lcopy;
  q = strchr(p, ':');
  while (q != NULL) {
    *q = '\0';
    if (strcasecmp(p, hname) == 0) {
      rc = 0;
      if (do_tick)
        tick[p - lcopy] = '_';
      goto BAIL;
    }
    p = q + 1;
    q = strchr(p, ':');
  }
  if (strcasecmp(p, hname) == 0) {
    rc = 0;
    if (do_tick)
      tick[p - lcopy] = '_';
  }
BAIL:
  free(hname);
  free(lcopy);
  return rc;
}


x86 assembly (clang, -O0):
<header_name_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0xffffffff,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11b2 <header_name_match+0x42>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1332 <header_name_match+0x1c2>
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e3 <header_name_match+0x73>
movl   $0xffffff9c,-0x4(%rbp)
jmp    1332 <header_name_match+0x1c2>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1050 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1246 <header_name_match+0xd6>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffff9c,-0x4(%rbp)
jmp    1332 <header_name_match+0x1c2>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12d5 <header_name_match+0x165>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12b2 <header_name_match+0x142>
movl   $0x0,-0x44(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12ad <header_name_match+0x13d>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    131a <header_name_match+0x1aa>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
jmp    1260 <header_name_match+0xf0>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1315 <header_name_match+0x1a5>
movl   $0x0,-0x44(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1310 <header_name_match+0x1a0>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    1315 <header_name_match+0x1a5>
jmp    131a <header_name_match+0x1aa>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header_name_match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%rbp
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     124e <header_name_match+0xde>
mov    %rax,%rbx
sub    %ebp,%ebx
lea    0x1(%rbx),%r15d
mov    %r15d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1256 <header_name_match+0xe6>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1070 <memset@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <strncpy@plt>
mov    %r14,%rdi
call   1090 <strdup@plt>
test   %rax,%rax
je     125e <header_name_match+0xee>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %r15,%rbp
test   %rax,%rax
je     122f <header_name_match+0xbf>
mov    %rax,%rbx
mov    %r15,%rbp
nopl   (%rax)
movb   $0x0,(%rbx)
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1269 <header_name_match+0xf9>
mov    %rbx,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <header_name_match+0x90>
mov    %r13d,%ebx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strcasecmp@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
jne    1279 <header_name_match+0x109>
test   %ebx,%ebx
jne    126e <header_name_match+0xfe>
jmp    1276 <header_name_match+0x106>
mov    $0xffffffff,%r13d
jmp    1289 <header_name_match+0x119>
mov    $0xffffff9c,%r13d
jmp    1289 <header_name_match+0x119>
mov    $0xffffff9c,%r13d
mov    %r12,%r15
jmp    1281 <header_name_match+0x111>
test   %r13d,%r13d
je     1276 <header_name_match+0x106>
sub    %r15,%rbp
movb   $0x5f,(%r14,%rbp,1)
xor    %r13d,%r13d
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @header_name_match(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 -1, i32* %12
%14 = load i8*, i8** %5
%15 = call i8* @strchr(i8* %14, i8 signext 58)
store i8* %15, i8** %13
%16 = load i8*, i8** %13
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i32, i32* %12
store i32 %19, i32* %4
br label %112
20: ; preds = %3
%21 = load i8*, i8** %13
%22 = load i8*, i8** %5
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = add nsw i64 %25, 1
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %20
store i32 -100, i32* %4
br label %112
32: ; preds = %20
%33 = load i8*, i8** %8
%34 = load i8*, i8** %13
%35 = load i8*, i8** %5
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = add nsw i64 %38, 1
%40 = trunc i64 %39 to i32
%41 = call i32 @memset(i8* %33, i32 0, i32 %40)
%42 = load i8*, i8** %8
%43 = load i8*, i8** %5
%44 = load i8*, i8** %13
%45 = load i8*, i8** %5
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = trunc i64 %48 to i32
%50 = call i32 @strncpy(i8* %42, i8* %43, i32 %49)
%51 = load i8*, i8** %6
%52 = call i8* @strdup(i8* %51)
store i8* %52, i8** %9
%53 = load i8*, i8** %9
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %58
55: ; preds = %32
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
store i32 -100, i32* %4
br label %112
58: ; preds = %32
%59 = load i8*, i8** %9
store i8* %59, i8** %10
%60 = load i8*, i8** %10
%61 = call i8* @strchr(i8* %60, i8 signext 58)
store i8* %61, i8** %11
br label %62
62: ; preds = %83, %58
%63 = load i8*, i8** %11
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %88
65: ; preds = %62
%66 = load i8*, i8** %11
store i8 0, i8* %66
%67 = load i8*, i8** %10
%68 = load i8*, i8** %8
%69 = call i64 @strcasecmp(i8* %67, i8* %68)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %83
71: ; preds = %65
store i32 0, i32* %12
%72 = load i32, i32* %7
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %82
74: ; preds = %71
%75 = load i8*, i8** %6
%76 = load i8*, i8** %10
%77 = load i8*, i8** %9
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
%81 = getelementptr inbounds i8, i8* %75, i64 %80
store i8 95, i8* %81
br label %82
82: ; preds = %74, %71
br label %106
83: ; preds = %65
%84 = load i8*, i8** %11
%85 = getelementptr inbounds i8, i8* %84, i64 1
store i8* %85, i8** %10
%86 = load i8*, i8** %10
%87 = call i8* @strchr(i8* %86, i8 signext 58)
store i8* %87, i8** %11
br label %62
88: ; preds = %62
%89 = load i8*, i8** %10
%90 = load i8*, i8** %8
%91 = call i64 @strcasecmp(i8* %89, i8* %90)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %105
93: ; preds = %88
store i32 0, i32* %12
%94 = load i32, i32* %7
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %104
96: ; preds = %93
%97 = load i8*, i8** %6
%98 = load i8*, i8** %10
%99 = load i8*, i8** %9
%100 = ptrtoint i8* %98 to i64
%101 = ptrtoint i8* %99 to i64
%102 = sub i64 %100, %101
%103 = getelementptr inbounds i8, i8* %97, i64 %102
store i8 95, i8* %103
br label %104
104: ; preds = %96, %93
br label %105
105: ; preds = %104, %88
br label %106
106: ; preds = %105, %82
%107 = load i8*, i8** %8
%108 = call i32 @free(i8* %107)
%109 = load i8*, i8** %9
%110 = call i32 @free(i8* %109)
%111 = load i32, i32* %12
store i32 %111, i32* %4
br label %112
112: ; preds = %106, %55, %31, %18
%113 = load i32, i32* %4
ret i32 %113
}

LLVM IR (-O2):
define i32 @header_name_match(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %52, label %6
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = add i32 %10, 1
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %52, label %14
14: ; preds = %6
%15 = tail call i32 @memset(i8* %12, i32 0, i32 %11)
%16 = tail call i32 @strncpy(i8* %12, i8* %0, i32 %10)
%17 = tail call i8* @strdup(i8* %1)
%18 = icmp eq i8* %17, null
br i1 %18, label %48, label %19
19: ; preds = %14
%20 = tail call i8* @strchr(i8* %17, i8 signext 58)
%21 = icmp eq i8* %20, null
br i1 %21, label %33, label %22
22: ; preds = %19, %29
%23 = phi i8* [ %31, %29 ], [ %20, %19 ]
%24 = phi i8* [ %30, %29 ], [ %17, %19 ]
store i8 0, i8* %23
%25 = tail call i64 @strcasecmp(i8* %24, i8* %12)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = icmp eq i32 %2, 0
br i1 %28, label %45, label %39
29: ; preds = %22
%30 = getelementptr inbounds i8, i8* %23, i64 1
%31 = tail call i8* @strchr(i8* %30, i8 signext 58)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %22
33: ; preds = %29, %19
%34 = phi i8* [ %17, %19 ], [ %30, %29 ]
%35 = tail call i64 @strcasecmp(i8* %34, i8* %12)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = icmp eq i32 %2, 0
br i1 %38, label %45, label %39
39: ; preds = %37, %27
%40 = phi i8* [ %24, %27 ], [ %34, %37 ]
%41 = ptrtoint i8* %40 to i64
%42 = ptrtoint i8* %17 to i64
%43 = sub i64 %41, %42
%44 = getelementptr inbounds i8, i8* %1, i64 %43
store i8 95, i8* %44
br label %45
45: ; preds = %39, %33, %37, %27
%46 = phi i32 [ 0, %27 ], [ 0, %37 ], [ -1, %33 ], [ 0, %39 ]
%47 = tail call i32 @free(i8* %12)
br label %48
48: ; preds = %14, %45
%49 = phi i8* [ %17, %45 ], [ %12, %14 ]
%50 = phi i32 [ %46, %45 ], [ -100, %14 ]
%51 = tail call i32 @free(i8* %49)
br label %52
52: ; preds = %48, %6, %3
%53 = phi i32 [ -1, %3 ], [ -100, %6 ], [ %50, %48 ]
ret i32 %53
}