#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 time_t;
struct tm {
  int tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ gmtime_r(int *, struct tm *);
int /*<<< orphan*/ localtime_r(int *, struct tm *);
int mktime(struct tm *);
char *strptime(char *, char *, struct tm *);
int /*<<< orphan*/ stub1(int *, struct tm *);
int stub2(struct tm *);
int stub3(struct tm *);
int /*<<< orphan*/ stub4(int *, struct tm *);
int /*<<< orphan*/ time(int *);
int timegm(struct tm *);
int syslog_date(char *line, struct tm *date) {
  char *cursor;
  time_t now, offset;
  time(&now);
  (1 ? gmtime_r : localtime_r)(&now, date);
  if ((cursor = strptime(line, " %b %d %H:%M:%S ", date))) {
    offset = now - (1 ? timegm : mktime)(date);
    date->tm_year += (offset - 15778800) / 31557600;
    now = (1 ? timegm : mktime)(date);
  }
  (1 ? gmtime_r : localtime_r)(&now, date);
  return cursor ? cursor - line : 0;
}


x86 assembly (clang, -O0):
<syslog_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <time@plt>
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
call   1030 <gmtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1060 <strptime@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c7 <syslog_date+0x87>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <timegm@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sub    $0xf0c3f0,%eax
mov    $0x1e187e0,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <timegm@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
call   1030 <gmtime_r@plt>
cmpq   $0x0,-0x18(%rbp)
je     11f3 <syslog_date+0xb3>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    11fe <syslog_date+0xbe>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11fe <syslog_date+0xbe>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<syslog_date>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x4(%rsp),%r15
mov    %r15,%rdi
call   1040 <time@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <gmtime_r@plt>
lea    0xe94(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <strptime@plt>
mov    %rax,%r15
test   %rax,%rax
je     11b8 <syslog_date+0x78>
mov    0x4(%rsp),%ebp
mov    %rbx,%rdi
call   1050 <timegm@plt>
sub    %eax,%ebp
add    $0xff0f3c10,%ebp
movslq %ebp,%rax
imul   $0x11032d79,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x35,%rax
add    %ecx,%eax
add    %eax,(%rbx)
mov    %rbx,%rdi
call   1050 <timegm@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <gmtime_r@plt>
mov    %r15d,%ecx
sub    %r14d,%ecx
xor    %eax,%eax
test   %r15,%r15
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [17 x i8] c" %b %d %H:%M:%S \00"
define i32 @syslog_date(i8* %0, %struct.tm* %1) {
%3 = alloca i8*
%4 = alloca %struct.tm*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store %struct.tm* %1, %struct.tm** %4
%8 = call i32 @time(i32* %6)
%9 = load %struct.tm*, %struct.tm** %4
%10 = call i32 @gmtime_r(i32* %6, %struct.tm* %9)
%11 = load i8*, i8** %3
%12 = load %struct.tm*, %struct.tm** %4
%13 = call i8* @strptime(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %struct.tm* %12)
store i8* %13, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %29
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load %struct.tm*, %struct.tm** %4
%18 = call i32 @timegm(%struct.tm* %17)
%19 = sub nsw i32 %16, %18
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = sub nsw i32 %20, 15778800
%22 = sdiv i32 %21, 31557600
%23 = load %struct.tm*, %struct.tm** %4
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = add nsw i32 %25, %22
store i32 %26, i32* %24
%27 = load %struct.tm*, %struct.tm** %4
%28 = call i32 @timegm(%struct.tm* %27)
store i32 %28, i32* %6
br label %29
29: ; preds = %15, %2
%30 = load %struct.tm*, %struct.tm** %4
%31 = call i32 @gmtime_r(i32* %6, %struct.tm* %30)
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %5
%36 = load i8*, i8** %3
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
br label %41
40: ; preds = %29
br label %41
41: ; preds = %40, %34
%42 = phi i64 [ %39, %34 ], [ 0, %40 ]
%43 = trunc i64 %42 to i32
ret i32 %43
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [17 x i8] c" %b %d %H:%M:%S \00"
define i32 @syslog_date(i8* %0, %struct.tm* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @time(i32* %3)
%6 = call i32 @gmtime_r(i32* %3, %struct.tm* %1)
%7 = call i8* @strptime(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %struct.tm* %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %19, label %9
9: ; preds = %2
%10 = load i32, i32* %3
%11 = call i32 @timegm(%struct.tm* %1)
%12 = add i32 %10, -15778800
%13 = sub i32 %12, %11
%14 = sdiv i32 %13, 31557600
%15 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %14, %16
store i32 %17, i32* %15
%18 = call i32 @timegm(%struct.tm* %1)
store i32 %18, i32* %3
br label %19
19: ; preds = %9, %2
%20 = call i32 @gmtime_r(i32* %3, %struct.tm* %1)
%21 = ptrtoint i8* %7 to i64
%22 = ptrtoint i8* %0 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = select i1 %8, i32 0, i32 %24
ret i32 %25
}