#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_year;
  int tm_mon;
  int tm_mday;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
char *approxidate_alpha(char const *, struct tm *, struct tm *, int *, int *);
char *approxidate_digit(char const *, struct tm *, int *);
scalar_t__ isalpha(unsigned char);
scalar_t__ isdigit(unsigned char);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ pending_number(struct tm *, int *);
unsigned long update_tm(struct tm *, struct tm *, int /*<<< orphan*/);
unsigned long approxidate_str(const char *date, const struct timeval *tv,
                              int *error_ret) {
  int number = 0;
  int touched = 0;
  struct tm tm, now;
  time_t time_sec;
  time_sec = tv->tv_sec;
  localtime_r(&time_sec, &tm);
  now = tm;
  tm.tm_year = -1;
  tm.tm_mon = -1;
  tm.tm_mday = -1;
  for (;;) {
    unsigned char c = *date;
    if (!c)
      break;
    date++;
    if (isdigit(c)) {
      pending_number(&tm, &number);
      date = approxidate_digit(date - 1, &tm, &number);
      touched = 1;
      continue;
    }
    if (isalpha(c))
      date = approxidate_alpha(date - 1, &tm, &now, &number, &touched);
  }
  pending_number(&tm, &number);
  if (!touched)
    *error_ret = 1;
  return update_tm(&tm, &now, 0);
}


x86 assembly (clang, -O0):
<approxidate_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
lea    -0x44(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <localtime_r@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0xffffffff,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x45(%rbp)
cmpb   $0x0,-0x45(%rbp)
jne    11e3 <approxidate_str+0x73>
jmp    126d <approxidate_str+0xfd>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movzbl -0x45(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1234 <approxidate_str+0xc4>
lea    -0x30(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <pending_number@plt>
mov    -0x8(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <approxidate_digit@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    11cb <approxidate_str+0x5b>
movzbl -0x45(%rbp),%edi
call   1090 <isalpha@plt>
cmp    $0x0,%rax
je     1268 <approxidate_str+0xf8>
mov    -0x8(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1060 <approxidate_alpha@plt>
mov    %rax,-0x8(%rbp)
jmp    11cb <approxidate_str+0x5b>
lea    -0x30(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <pending_number@plt>
cmpl   $0x0,-0x20(%rbp)
jne    128e <approxidate_str+0x11e>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
xor    %edx,%edx
call   1050 <update_tm@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<approxidate_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,0x30(%rsp)
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    (%rsi),%eax
mov    %eax,0x1c(%rsp)
lea    0x1c(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <localtime_r@plt>
mov    0x18(%rsp),%eax
mov    %eax,0x28(%rsp)
mov    0x10(%rsp),%rax
mov    %rax,0x20(%rsp)
movq   $0xffffffffffffffff,0x10(%rsp)
ff ff
movl   $0xffffffff,0x18(%rsp)
ff
mov    (%rbx),%al
test   %al,%al
je     1258 <approxidate_str+0xe8>
lea    0x10(%rsp),%r15
lea    0x20(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%rbp
jmp    121b <approxidate_str+0xab>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <pending_number@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1080 <approxidate_digit@plt>
mov    %rax,%rbx
movl   $0x1,0x8(%rsp)
movzbl (%rbx),%eax
test   %al,%al
je     1258 <approxidate_str+0xe8>
movzbl %al,%r14d
mov    %r14d,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    11f0 <approxidate_str+0x80>
mov    %r14d,%edi
call   1090 <isalpha@plt>
test   %rax,%rax
je     1252 <approxidate_str+0xe2>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1060 <approxidate_alpha@plt>
mov    %rax,%rbx
jmp    1214 <approxidate_str+0xa4>
add    $0x1,%rbx
jmp    1214 <approxidate_str+0xa4>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1070 <pending_number@plt>
cmpl   $0x0,0x8(%rsp)
jne    1279 <approxidate_str+0x109>
mov    0x30(%rsp),%rax
movl   $0x1,(%rax)
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
xor    %edx,%edx
call   1050 <update_tm@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32 }
define i64 @approxidate_str(i8* %0, %struct.timeval* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca %struct.timeval*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.tm
%10 = alloca %struct.tm
%11 = alloca i32
%12 = alloca i8
store i8* %0, i8** %4
store %struct.timeval* %1, %struct.timeval** %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32 0, i32* %8
%13 = load %struct.timeval*, %struct.timeval** %5
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %11
%16 = call i32 @localtime_r(i32* %11, %struct.tm* %9)
%17 = bitcast %struct.tm* %10 to i8*
%18 = bitcast %struct.tm* %9 to i8*
%19 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
store i32 -1, i32* %19
%20 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
store i32 -1, i32* %20
%21 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 2
store i32 -1, i32* %21
br label %22
22: ; preds = %47, %34, %3
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
store i8 %24, i8* %12
%25 = load i8, i8* %12
%26 = icmp ne i8 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
br label %48
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
%31 = load i8, i8* %12
%32 = call i64 @isdigit(i8 zeroext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = call i32 @pending_number(%struct.tm* %9, i32* %7)
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 -1
%38 = call i8* @approxidate_digit(i8* %37, %struct.tm* %9, i32* %7)
store i8* %38, i8** %4
store i32 1, i32* %8
br label %22
39: ; preds = %28
%40 = load i8, i8* %12
%41 = call i64 @isalpha(i8 zeroext %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 -1
%46 = call i8* @approxidate_alpha(i8* %45, %struct.tm* %9, %struct.tm* %10, i32* %7, i32* %8)
store i8* %46, i8** %4
br label %47
47: ; preds = %43, %39
br label %22
48: ; preds = %27
%49 = call i32 @pending_number(%struct.tm* %9, i32* %7)
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %48
%53 = load i32*, i32** %6
store i32 1, i32* %53
br label %54
54: ; preds = %52, %48
%55 = call i64 @update_tm(%struct.tm* %9, %struct.tm* %10, i32 0)
ret i64 %55
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32 }
define i64 @approxidate_str(i8* %0, %struct.timeval* nocapture %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tm
%7 = alloca %struct.tm
%8 = alloca i32
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%11 = bitcast %struct.tm* %6 to i8*
%12 = bitcast %struct.tm* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %8
%16 = call i32 @localtime_r(i32* %8, %struct.tm* %6)
%17 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
store i32 -1, i32* %17
%18 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
store i32 -1, i32* %18
%19 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
store i32 -1, i32* %19
%20 = load i8, i8* %0
%21 = icmp eq i8 %20, 0
br i1 %21, label %40, label %22
22: ; preds = %3, %36
%23 = phi i8 [ %38, %36 ], [ %20, %3 ]
%24 = phi i8* [ %37, %36 ], [ %0, %3 ]
%25 = call i64 @isdigit(i8 zeroext %23)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = call i32 @pending_number(%struct.tm* %6, i32* %4)
%29 = call i8* @approxidate_digit(i8* %24, %struct.tm* %6, i32* %4)
store i32 1, i32* %5
br label %36
30: ; preds = %22
%31 = getelementptr inbounds i8, i8* %24, i64 1
%32 = call i64 @isalpha(i8 zeroext %23)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i8* @approxidate_alpha(i8* %24, %struct.tm* %6, %struct.tm* %7, i32* %4, i32* %5)
br label %36
36: ; preds = %30, %34, %27
%37 = phi i8* [ %29, %27 ], [ %35, %34 ], [ %31, %30 ]
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %22
40: ; preds = %36, %3
%41 = call i32 @pending_number(%struct.tm* %6, i32* %4)
%42 = load i32, i32* %5
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 1, i32* %2
br label %45
45: ; preds = %44, %40
%46 = call i64 @update_tm(%struct.tm* %6, %struct.tm* %7, i32 0)
ret i64 %46
}