#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ error_code(int /*<<< orphan*/, char *, char *, char *,
                              char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void log_response(char *remote_addr, char *user_identifier, char *user_name,
                  char *date, char *request, int http_response, int bytes) {
  char str_http_response[16];
  char str_bytes[256];
  struct tm *tm = NULL;
  time_t now;
  if (http_response != -1)
    sprintf(str_http_response, "%d", http_response);
  else
    strcpy(str_http_response, "-");
  if (bytes != -1)
    sprintf(str_bytes, "%d", bytes);
  else
    strcpy(str_bytes, "-");
  if (!date) {
    date = calloc(256, sizeof(char));
    now = time(NULL);
    tm = localtime(&now);
    strftime(date, 256, "[%d/%b/%Y:%H:%M:%S %z]", tm);
  }
  if (!user_name) {
    user_name = getenv("REMOTE_USER");
    if (!user_name)
      user_name = "-";
  }
  error_code(0, "--%s %s %s %s \"%s\" %s %s %s", remote_addr, user_identifier,
             user_name, date, request, str_http_response, str_bytes,
             (getenv("HTTP_HOST") ? getenv("HTTP_HOST") : ""));
  if (tm)
    (free(date), (date) = NULL);
}


x86 assembly (clang, -O0):
<log_response>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x1b8,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movq   $0x0,-0x158(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     11e4 <log_response+0x54>
lea    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xe26(%rip),%rsi
call   10b0 <sprintf@plt>
jmp    11f4 <log_response+0x64>
lea    -0x50(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcpy@plt>
cmpl   $0xffffffff,0x10(%rbp)
je     1219 <log_response+0x89>
lea    -0x150(%rbp),%rdi
mov    0x10(%rbp),%edx
lea    0xdf1(%rip),%rsi
call   10b0 <sprintf@plt>
jmp    122c <log_response+0x9c>
lea    -0x150(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1060 <strcpy@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1288 <log_response+0xf8>
mov    $0x100,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x15c(%rbp)
lea    -0x15c(%rbp),%rdi
call   1050 <localtime@plt>
mov    %rax,-0x158(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x158(%rbp),%rcx
mov    $0x100,%esi
lea    0xd82(%rip),%rdx
call   10a0 <strftime@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12be <log_response+0x12e>
lea    0xd82(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12b9 <log_response+0x129>
lea    0xd4e(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12be <log_response+0x12e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x198(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x190(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x188(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x178(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x170(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    0xd2f(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     133c <log_response+0x1ac>
lea    0xd19(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x1a0(%rbp)
jmp    134f <log_response+0x1bf>
lea    0xcc1(%rip),%rax
mov    %rax,-0x1a0(%rbp)
jmp    134f <log_response+0x1bf>
mov    -0x168(%rbp),%r10
mov    -0x170(%rbp),%r11
mov    -0x178(%rbp),%rbx
mov    -0x180(%rbp),%r9
mov    -0x188(%rbp),%r8
mov    -0x190(%rbp),%rcx
mov    -0x198(%rbp),%rdx
mov    -0x1a0(%rbp),%rax
xor    %edi,%edi
lea    0xc98(%rip),%rsi
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1080 <error_code@plt>
cmpq   $0x0,-0x158(%rbp)
je     13c7 <log_response+0x237>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x28(%rbp)
add    $0x1b8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_response>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r8,0x8(%rsp)
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x160(%rsp),%ebp
cmp    $0xffffffff,%r9d
je     1287 <log_response+0xf7>
lea    0xe36(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r9d,%edx
call   10b0 <sprintf@plt>
cmp    $0xffffffff,%ebp
je     12a1 <log_response+0x111>
lea    0xe19(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %ebp,%edx
call   10b0 <sprintf@plt>
test   %r13,%r13
je     12bb <log_response+0x12b>
xor    %r14d,%r14d
test   %rbx,%rbx
jne    121e <log_response+0x8e>
lea    0xe11(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xde9(%rip),%rbx
cmovne %rax,%rbx
lea    0xe1f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xdd0(%rip),%rbp
cmovne %rax,%rbp
lea    0x20(%rsp),%rax
lea    0x10(%rsp),%r10
lea    0xddf(%rip),%rsi
xor    %edi,%edi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
mov    %r13,%r9
push   %rbp
push   %rax
push   %r10
push   0x20(%rsp)
call   1080 <error_code@plt>
add    $0x20,%rsp
test   %r14,%r14
je     1275 <log_response+0xe5>
mov    %r13,%rdi
call   1040 <free@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd75(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <strcpy@plt>
cmp    $0xffffffff,%ebp
jne    11e0 <log_response+0x50>
lea    0xd5b(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1060 <strcpy@plt>
test   %r13,%r13
jne    11fc <log_response+0x6c>
mov    $0x100,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r13
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1050 <localtime@plt>
mov    %rax,%r14
lea    0xd19(%rip),%rdx
mov    %r13,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   10a0 <strftime@plt>
test   %rbx,%rbx
jne    121e <log_response+0x8e>
jmp    1204 <log_response+0x74>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [23 x i8] c"[%d/%b/%Y:%H:%M:%S %z]\00"
@.str.3 = [12 x i8] c"REMOTE_USER\00"
@.str.4 = [28 x i8] c"--%s %s %s %s \22%s\22 %s %s %s\00"
@.str.5 = [10 x i8] c"HTTP_HOST\00"
@.str.6 = [1 x i8] zeroinitializer
define void @log_response(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca [16 x i8]
%16 = alloca [256 x i8]
%17 = alloca %struct.tm*
%18 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i32 %6, i32* %14
store %struct.tm* null, %struct.tm** %17
%19 = load i32, i32* %13
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %7
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%23 = load i32, i32* %13
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %28
25: ; preds = %7
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %14
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%33 = load i32, i32* %14
%34 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %38
35: ; preds = %28
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %35, %31
%39 = load i8*, i8** %11
%40 = icmp ne i8* %39, null
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = call i8* @calloc(i32 256, i32 1)
store i8* %42, i8** %11
%43 = call i32 @time(i32* null)
store i32 %43, i32* %18
%44 = call %struct.tm* @localtime(i32* %18)
store %struct.tm* %44, %struct.tm** %17
%45 = load i8*, i8** %11
%46 = load %struct.tm*, %struct.tm** %17
%47 = call i32 @strftime(i8* %45, i32 256, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %46)
br label %48
48: ; preds = %41, %38
%49 = load i8*, i8** %10
%50 = icmp ne i8* %49, null
br i1 %50, label %57, label %51
51: ; preds = %48
%52 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i8* %52, i8** %10
%53 = load i8*, i8** %10
%54 = icmp ne i8* %53, null
br i1 %54, label %56, label %55
55: ; preds = %51
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %56
56: ; preds = %55, %51
br label %57
57: ; preds = %56, %48
%58 = load i8*, i8** %8
%59 = load i8*, i8** %9
%60 = load i8*, i8** %10
%61 = load i8*, i8** %11
%62 = load i8*, i8** %12
%63 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%65 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %69
67: ; preds = %57
%68 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %70
69: ; preds = %57
br label %70
70: ; preds = %69, %67
%71 = phi i8* [ %68, %67 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %69 ]
%72 = call i32 @error_code(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %58, i8* %59, i8* %60, i8* %61, i8* %62, i8* %63, i8* %64, i8* %71)
%73 = load %struct.tm*, %struct.tm** %17
%74 = icmp ne %struct.tm* %73, null
br i1 %74, label %75, label %78
75: ; preds = %70
%76 = load i8*, i8** %11
%77 = call i32 @free(i8* %76)
store i8* null, i8** %11
br label %78
78: ; preds = %75, %70
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [23 x i8] c"[%d/%b/%Y:%H:%M:%S %z]\00"
@.str.3 = [12 x i8] c"REMOTE_USER\00"
@.str.4 = [28 x i8] c"--%s %s %s %s \22%s\22 %s %s %s\00"
@.str.5 = [10 x i8] c"HTTP_HOST\00"
@.str.6 = [1 x i8] zeroinitializer
define void @log_response(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca [16 x i8]
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%13 = bitcast i32* %10 to i8*
%14 = icmp eq i32 %5, -1
br i1 %14, label %17, label %15
15: ; preds = %7
%16 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %19
17: ; preds = %7
%18 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = icmp eq i32 %6, -1
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %25
23: ; preds = %19
%24 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
%26 = icmp eq i8* %3, null
br i1 %26, label %27, label %32
27: ; preds = %25
%28 = call dereferenceable_or_null(256) i8* @calloc(i32 256, i32 1)
%29 = call i32 @time(i32* null)
store i32 %29, i32* %10
%30 = call %struct.tm* @localtime(i32* %10)
%31 = call i32 @strftime(i8* %28, i32 256, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %30)
br label %32
32: ; preds = %27, %25
%33 = phi i8* [ %3, %25 ], [ %28, %27 ]
%34 = phi %struct.tm* [ null, %25 ], [ %30, %27 ]
%35 = icmp eq i8* %2, null
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i8* %37, null
%39 = select i1 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %37
br label %40
40: ; preds = %36, %32
%41 = phi i8* [ %2, %32 ], [ %39, %36 ]
%42 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%43 = icmp eq i8* %42, null
%44 = select i1 %43, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* %42
%45 = call i32 @error_code(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %1, i8* %41, i8* %33, i8* %4, i8* %11, i8* %12, i8* %44)
%46 = icmp eq %struct.tm* %34, null
br i1 %46, label %49, label %47
47: ; preds = %40
%48 = call i32 @free(i8* %33)
br label %49
49: ; preds = %47, %40
ret void
}