#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 */
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long long, int, int,
                           int /*<<< orphan*/);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ printf(char *, int, char const *, int, char const *);
int /*<<< orphan*/ stderr;
int respond(int status, const char *reason) {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  fprintf(stderr, "%lld.%04d %d %s\n", (long long)tv.tv_sec,
          (int)tv.tv_usec / 1000, status, getenv("REMOTE_ADDR"));
  int ok =
      (printf(
           "Status: %d %s\nContent-Type: text/plain; charset=utf-8\n\n%d %s\n",
           status, reason, status, reason) >= 0);
  return ok ? 0 : 1;
}


x86 assembly (clang, -O0):
<respond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    %eax,%r9d
lea    0xe57(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<respond>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%r12d
mov    0x8(%rsp),%r15
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x26,%rbx
add    %eax,%ebx
lea    0xe88(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe6b(%rip),%rsi
mov    %r12d,%edi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
call   1060 <fprintf@plt>
lea    0xe6e(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %r14,%r8
call   1040 <printf@plt>
shr    $0x3f,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [17 x i8] c"%lld.%04d %d %s\0A\00"
@.str.1 = [12 x i8] c"REMOTE_ADDR\00"
@.str.2 = [62 x i8] c"Status: %d %s\0AContent-Type: text/plain; charset=utf-8\0A\0A%d %s\0A\00"
define i32 @respond(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.timeval
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%8 = load i32, i32* @stderr
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = sdiv i32 %13, 1000
%15 = load i32, i32* %3
%16 = call i32 @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %10, i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %3
%19 = load i8*, i8** %4
%20 = load i32, i32* %3
%21 = load i8*, i8** %4
%22 = call i64 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %18, i8* %19, i32 %20, i8* %21)
%23 = icmp sge i64 %22, 0
%24 = zext i1 %23 to i32
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 0, i32 1
ret i32 %28
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [17 x i8] c"%lld.%04d %d %s\0A\00"
@.str.1 = [12 x i8] c"REMOTE_ADDR\00"
@.str.2 = [62 x i8] c"Status: %d %s\0AContent-Type: text/plain; charset=utf-8\0A\0A%d %s\0A\00"
define i32 @respond(i32 %0, i8* %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = load i32, i32* @stderr
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = sdiv i32 %11, 1000
%13 = tail call i32 @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %8, i32 %12, i32 %0, i32 %13)
%15 = tail call i64 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %1, i32 %0, i8* %1)
%16 = lshr i64 %15, 63
%17 = trunc i64 %16 to i32
ret i32 %17
}