#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;
};

/* Variables and functions */
int atoi(char const *);
int /*<<< orphan*/ mkgmtime(struct tm *);
time_t jtr_parse_date(const char *str, struct tm *tm) {
  int dmy = atoi(str);
  if (dmy > 0) {
    tm->tm_year = dmy % 100 + 100;
    dmy = dmy / 100;
    tm->tm_mon = dmy % 100 - 1;
    dmy = dmy / 100;
    tm->tm_mday = dmy;
    return mkgmtime(tm);
  } else
    return 0;
}


x86 assembly (clang, -O0):
<jtr_parse_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11a6 <jtr_parse_date+0x86>
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x64,%edx
mov    -0x18(%rbp),%rax
mov    %edx,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
sub    $0x1,%edx
mov    -0x18(%rbp),%rax
mov    %edx,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <mkgmtime@plt>
mov    %eax,-0x4(%rbp)
jmp    11ad <jtr_parse_date+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jtr_parse_date>:
push   %rbx
mov    %rsi,%rbx
call   1040 <atoi@plt>
test   %eax,%eax
jle    1174 <jtr_parse_date+0x54>
mov    %eax,%ecx
imul   $0x51eb851f,%rcx,%rdx
shr    $0x25,%rdx
imul   $0x64,%edx,%esi
neg    %esi
add    %esi,%eax
add    $0x64,%eax
mov    %eax,(%rbx)
imul   $0x51eb851f,%rdx,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
not    %eax
add    %edx,%eax
mov    %eax,0x4(%rbx)
mov    $0xd1b71759,%eax
imul   %rcx,%rax
shr    $0x2d,%rax
mov    %eax,0x8(%rbx)
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <mkgmtime@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define i32 @jtr_parse_date(i8* %0, %struct.tm* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.tm*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.tm* %1, %struct.tm** %5
%7 = load i8*, i8** %4
%8 = call i32 @atoi(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %2
%12 = load i32, i32* %6
%13 = srem i32 %12, 100
%14 = add nsw i32 %13, 100
%15 = load %struct.tm*, %struct.tm** %5
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* %6
%18 = sdiv i32 %17, 100
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = srem i32 %19, 100
%21 = sub nsw i32 %20, 1
%22 = load %struct.tm*, %struct.tm** %5
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 1
store i32 %21, i32* %23
%24 = load i32, i32* %6
%25 = sdiv i32 %24, 100
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = load %struct.tm*, %struct.tm** %5
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 2
store i32 %26, i32* %28
%29 = load %struct.tm*, %struct.tm** %5
%30 = call i32 @mkgmtime(%struct.tm* %29)
store i32 %30, i32* %3
br label %32
31: ; preds = %2
store i32 0, i32* %3
br label %32
32: ; preds = %31, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define i32 @jtr_parse_date(i8* nocapture %0, %struct.tm* %1) {
%3 = tail call i32 @atoi(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = urem i32 %3, 100
%7 = add nuw nsw i32 %6, 100
%8 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
store i32 %7, i32* %8
%9 = udiv i32 %3, 100
%10 = urem i32 %9, 100
%11 = add nsw i32 %10, -1
%12 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
store i32 %11, i32* %12
%13 = udiv i32 %3, 10000
%14 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @mkgmtime(%struct.tm* %1)
br label %16
16: ; preds = %2, %5
%17 = phi i32 [ %15, %5 ], [ 0, %2 ]
ret i32 %17
}