#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 tm_min;
  int tm_hour;
  int tm_yday;
};

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ const *);
struct tm *localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
size_t strftime(char *, int, char *, struct tm *);
const char *mkhttpdlogtime(const time_t *t) {
  static char buf[128];
  struct tm *gmt = gmtime(t);
  int gmt_min, gmt_hour, gmt_yday, day_offset;
  size_t len;
  struct tm *lt;
  int min_offset;
  gmt_min = gmt->tm_min;
  gmt_hour = gmt->tm_hour;
  gmt_yday = gmt->tm_yday;
  lt = localtime(t);
  day_offset = lt->tm_yday - gmt_yday;
  if (day_offset > 1)
    day_offset = -1;
  else if (day_offset < -1)
    day_offset = 1;
  min_offset = day_offset * 1440 + (lt->tm_hour - gmt_hour) * 60 +
               (lt->tm_min - gmt_min);
  len = strftime(buf, 127 - 5, "%d/%b/%Y:%H:%M:%S ", lt);
  snprintf(buf + len, 128 - len, "%+03d%02d", (min_offset / 60) % 24,
           min_offset % 60);
  return buf;
}


x86 assembly (clang, -O0):
<mkhttpdlogtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <gmtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jle    11a6 <mkhttpdlogtime+0x66>
movl   $0xffffffff,-0x20(%rbp)
jmp    11bc <mkhttpdlogtime+0x7c>
cmpl   $0xffffffff,-0x20(%rbp)
jge    11b7 <mkhttpdlogtime+0x77>
movl   $0x1,-0x20(%rbp)
jmp    11bc <mkhttpdlogtime+0x7c>
imul   $0x5a0,-0x20(%rbp),%eax
mov    -0x30(%rbp),%rcx
mov    0x4(%rcx),%ecx
sub    -0x18(%rbp),%ecx
imul   $0x3c,%ecx,%ecx
add    %ecx,%eax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%ecx
sub    -0x14(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rcx
lea    0x2e65(%rip),%rdi
mov    $0x7a,%esi
lea    0xe09(%rip),%rdx
call   1050 <strftime@plt>
mov    %rax,-0x28(%rbp)
lea    0x2e49(%rip),%rdi
add    -0x28(%rbp),%rdi
mov    $0x80,%eax
sub    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x34(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x34(%rbp),%eax
mov    $0x3c,%r8d
cltd
idiv   %r8d
mov    %edx,%r8d
lea    0xdd1(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2e02(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkhttpdlogtime>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <gmtime@plt>
mov    (%rax),%r15d
mov    0x4(%rax),%r14d
mov    0x8(%rax),%ebp
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    0x8(%rax),%ecx
sub    %ebp,%ecx
imul   $0x5a0,%ecx,%edx
cmp    $0xffffffff,%ecx
mov    $0x5a0,%esi
cmovge %edx,%esi
cmp    $0x2,%ecx
mov    $0xfffffa60,%ecx
cmovl  %esi,%ecx
mov    (%rax),%edx
sub    %r15d,%edx
mov    0x4(%rax),%esi
sub    %r14d,%esi
imul   $0x3c,%esi,%ebp
add    %edx,%ebp
add    %ecx,%ebp
lea    0x2eb5(%rip),%rbx
lea    0xe5e(%rip),%rdx
mov    %rbx,%rdi
mov    $0x7a,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
lea    (%rbx,%rax,1),%rdi
mov    $0x80,%esi
sub    %eax,%esi
movslq %ebp,%r8
imul   $0xffffffff88888889,%r8,%rax
shr    $0x20,%rax
add    %r8d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
movslq %eax,%rcx
imul   $0x2aaaaaab,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x22,%rax
add    %edx,%eax
shl    $0x3,%eax
lea    (%rax,%rax,2),%eax
imul   $0x3c,%ecx,%edx
sub    %eax,%ecx
sub    %edx,%r8d
lea    0xe0f(%rip),%rdx
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@mkhttpdlogtime.buf = internal global [128 x i8] zeroinitializer
@.str = [19 x i8] c"%d/%b/%Y:%H:%M:%S \00"
@.str.1 = [10 x i8] c"%+03d%02d\00"
define i8* @mkhttpdlogtime(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.tm*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca %struct.tm*
%10 = alloca i32
store i32* %0, i32** %2
%11 = load i32*, i32** %2
%12 = call %struct.tm* @gmtime(i32* %11)
store %struct.tm* %12, %struct.tm** %3
%13 = load %struct.tm*, %struct.tm** %3
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %4
%16 = load %struct.tm*, %struct.tm** %3
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 1
%18 = load i32, i32* %17
store i32 %18, i32* %5
%19 = load %struct.tm*, %struct.tm** %3
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 2
%21 = load i32, i32* %20
store i32 %21, i32* %6
%22 = load i32*, i32** %2
%23 = call %struct.tm* @localtime(i32* %22)
store %struct.tm* %23, %struct.tm** %9
%24 = load %struct.tm*, %struct.tm** %9
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 2
%26 = load i32, i32* %25
%27 = load i32, i32* %6
%28 = sub nsw i32 %26, %27
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %1
store i32 -1, i32* %7
br label %37
32: ; preds = %1
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 1, i32* %7
br label %36
36: ; preds = %35, %32
br label %37
37: ; preds = %36, %31
%38 = load i32, i32* %7
%39 = mul nsw i32 %38, 1440
%40 = load %struct.tm*, %struct.tm** %9
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 1
%42 = load i32, i32* %41
%43 = load i32, i32* %5
%44 = sub nsw i32 %42, %43
%45 = mul nsw i32 %44, 60
%46 = add nsw i32 %39, %45
%47 = load %struct.tm*, %struct.tm** %9
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = load i32, i32* %4
%51 = sub nsw i32 %49, %50
%52 = add nsw i32 %46, %51
store i32 %52, i32* %10
%53 = load %struct.tm*, %struct.tm** %9
%54 = call i64 @strftime(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mkhttpdlogtime.buf, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %53)
store i64 %54, i64* %8
%55 = load i64, i64* %8
%56 = getelementptr inbounds i8, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mkhttpdlogtime.buf, i64 0, i64 0), i64 %55
%57 = load i64, i64* %8
%58 = sub i64 128, %57
%59 = trunc i64 %58 to i32
%60 = load i32, i32* %10
%61 = sdiv i32 %60, 60
%62 = srem i32 %61, 24
%63 = load i32, i32* %10
%64 = srem i32 %63, 60
%65 = call i32 @snprintf(i8* %56, i32 %59, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %62, i32 %64)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mkhttpdlogtime.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@mkhttpdlogtime.buf = internal global [128 x i8] zeroinitializer
@.str = [19 x i8] c"%d/%b/%Y:%H:%M:%S \00"
@.str.1 = [10 x i8] c"%+03d%02d\00"
define i8* @mkhttpdlogtime(i32* %0) {
%2 = tail call %struct.tm* @gmtime(i32* %0)
%3 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
%8 = load i32, i32* %7
%9 = tail call %struct.tm* @localtime(i32* %0)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 2
%11 = load i32, i32* %10
%12 = sub nsw i32 %11, %8
%13 = icmp sgt i32 %12, 1
%14 = icmp slt i32 %12, -1
%15 = mul i32 %12, 1440
%16 = select i1 %14, i32 1440, i32 %15
%17 = select i1 %13, i32 -1440, i32 %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 1
%19 = load i32, i32* %18
%20 = sub nsw i32 %19, %6
%21 = mul nsw i32 %20, 60
%22 = getelementptr inbounds %struct.tm, %struct.tm* %9, i64 0, i32 0
%23 = load i32, i32* %22
%24 = sub nsw i32 %23, %4
%25 = add i32 %24, %21
%26 = add i32 %25, %17
%27 = tail call i64 @strftime(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mkhttpdlogtime.buf, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %9)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* @mkhttpdlogtime.buf, i64 0, i64 %27
%29 = trunc i64 %27 to i32
%30 = sub i32 128, %29
%31 = sdiv i32 %26, 60
%32 = srem i32 %31, 24
%33 = srem i32 %26, 60
%34 = tail call i32 @snprintf(i8* %28, i32 %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mkhttpdlogtime.buf, i64 0, i64 0)
}