#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*/ appendEnv(char ***, char *, char const *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcasecmp(char const *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
char toupper(char const);
void putHeader(char ***envpLoc, const char *headerName,
               const char *headerValue) {
  static const char *omitHeaders[] = {"Content-Length",    "Content-Type",
                                      "Authorization",     "Connection",
                                      "Transfer-Encoding", NULL};
  int i, len;
  char *nameBuf;
  for (i = 0; omitHeaders[i]; ++i) {
    if (!strcasecmp(headerName, omitHeaders[i]))
      return;
  }
  len = strlen(headerName);
  nameBuf = malloc(len + 6);
  strcpy(nameBuf, "HTTP_");
  for (i = 0; headerName[i]; ++i) {
    if (headerName[i] == '-')
      nameBuf[i + 5] = '_';
    else
      nameBuf[i + 5] = toupper(headerName[i]);
  }
  nameBuf[i + 5] = '\0';
  appendEnv(envpLoc, nameBuf, headerValue);
  free(nameBuf);
}


x86 assembly (clang, -O0):
<putHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rcx
lea    0x2eca(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
je     11da <putHeader+0x6a>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rcx
lea    0x2eb0(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11c7 <putHeader+0x57>
jmp    12aa <putHeader+0x13a>
jmp    11cc <putHeader+0x5c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118b <putHeader+0x1b>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x6,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1050 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     127f <putHeader+0x10f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    1249 <putHeader+0xd9>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    126c <putHeader+0xfc>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <toupper@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1271 <putHeader+0x101>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120c <putHeader+0x9c>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1090 <appendEnv@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putHeader>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xe77(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     1244 <putHeader+0xd4>
lea    0xe6f(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     1244 <putHeader+0xd4>
lea    0xe65(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     1244 <putHeader+0xd4>
lea    0xe5c(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     1244 <putHeader+0xd4>
lea    0xe54(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     1244 <putHeader+0xd4>
mov    %r12,%rdi
call   1070 <strlen@plt>
lea    0x6(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%r13
lea    0xe40(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
mov    $0x5,%ebx
jmp    1229 <putHeader+0xb9>
cs nopw 0x0(%rax,%rax,1)
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
movzbl -0x5(%r12,%rbx,1),%ecx
mov    $0x5f,%al
cmp    $0x2d,%cl
je     1220 <putHeader+0xb0>
test   %cl,%cl
je     124e <putHeader+0xde>
movsbl %cl,%edi
call   1060 <toupper@plt>
jmp    1220 <putHeader+0xb0>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %ebx,%eax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1090 <appendEnv@plt>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [15 x i8] c"Content-Length\00"
@.str.1 = [13 x i8] c"Content-Type\00"
@.str.2 = [14 x i8] c"Authorization\00"
@.str.3 = [11 x i8] c"Connection\00"
@.str.4 = [18 x i8] c"Transfer-Encoding\00"
@.str.5 = [6 x i8] c"HTTP_\00"
define void @putHeader(i8*** %0, i8* %1, i8* %2) {
%4 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %40, label %6
6: ; preds = %3
%7 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %40, label %9
9: ; preds = %6
%10 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %40, label %12
12: ; preds = %9
%13 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %40, label %15
15: ; preds = %12
%16 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %40, label %18
18: ; preds = %15
%19 = tail call i32 @strlen(i8* %1)
%20 = add nsw i32 %19, 6
%21 = tail call i8* @malloc(i32 %20)
%22 = tail call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %29, %18
%24 = phi i64 [ %33, %29 ], [ 0, %18 ]
%25 = getelementptr inbounds i8, i8* %1, i64 %24
%26 = load i8, i8* %25
switch i8 %26, label %27 [
i8 0, label %34
i8 45, label %29
]
27: ; preds = %23
%28 = tail call signext i8 @toupper(i8 signext %26)
br label %29
29: ; preds = %23, %27
%30 = phi i8 [ %28, %27 ], [ 95, %23 ]
%31 = add nuw nsw i64 %24, 5
%32 = getelementptr inbounds i8, i8* %21, i64 %31
store i8 %30, i8* %32
%33 = add nuw i64 %24, 1
br label %23
34: ; preds = %23
%35 = add i64 %24, 5
%36 = and i64 %35, 4294967295
%37 = getelementptr inbounds i8, i8* %21, i64 %36
store i8 0, i8* %37
%38 = tail call i32 @appendEnv(i8*** %0, i8* %21, i8* %2)
%39 = tail call i32 @free(i8* %21)
br label %40
40: ; preds = %3, %6, %9, %12, %15, %34
ret void
}