#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 {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ format_http_date(int /*<<< orphan*/ *, char *, size_t);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int current_http_date(char *dst, size_t len) {
  struct timeval tv;
  int res;
  res = gettimeofday(&tv, NULL);
  if (res < 0) {
    error("Error getting time of day");
    return -1;
  }
  format_http_date(&tv.tv_sec, dst, len);
  return 0;
}


x86 assembly (clang, -O0):
<current_http_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1172 <current_http_date+0x42>
lea    0xe9f(%rip),%rdi
call   1050 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <current_http_date+0x5a>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <format_http_date@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_http_date>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %eax,%eax
js     1163 <current_http_date+0x33>
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <format_http_date@plt>
jmp    1174 <current_http_date+0x44>
lea    0xe96(%rip),%rdi
call   1050 <error@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [26 x i8] c"Error getting time of day\00"
define i32 @current_http_date(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.timeval
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %18
13: ; preds = %2
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%15 = load i8*, i8** %4
%16 = load i64, i64* %5
%17 = call i32 @format_http_date(i32* %14, i8* %15, i64 %16)
store i32 0, i32* %3
br label %18
18: ; preds = %13, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [26 x i8] c"Error getting time of day\00"
define i32 @current_http_date(i8* %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %2
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%11 = call i32 @format_http_date(i32* %10, i8* %0, i64 %1)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ -1, %7 ], [ 0, %9 ]
ret i32 %13
}