#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 */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ sprintf(char *, char *, long);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void long_to_date(long l, int *y, int *m, int *d) {
  char year[32], month[32], day[32];
  sprintf(year, "%ld", l);
  if (strlen(year) != 8) {
    *y = *m = *d = -1;
    return;
  }
  strcpy(month, year + 4);
  strcpy(day, month + 2);
  year[4] = '\0';
  month[2] = '\0';
  *y = atoi(year);
  *m = atoi(month);
  *d = atoi(day);
}


x86 assembly (clang, -O0):
<long_to_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe96(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
je     11a4 <long_to_date+0x64>
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    1201 <long_to_date+0xc1>
lea    -0x60(%rbp),%rdi
lea    -0x40(%rbp),%rsi
add    $0x4,%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rsi
add    $0x2,%rsi
call   1030 <strcpy@plt>
movb   $0x0,-0x3c(%rbp)
movb   $0x0,-0x5e(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x60(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x80(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<long_to_date>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rdx
lea    0xea0(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jne    11ca <long_to_date+0x8a>
lea    0x4(%rsp),%rsi
lea    0x20(%rsp),%r13
mov    %r13,%rdi
call   1030 <strcpy@plt>
lea    0x22(%rsp),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
movb   $0x0,0x4(%rsp)
movb   $0x0,0x22(%rsp)
mov    %rsp,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r12)
mov    %r13,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r15)
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r14)
jmp    11e0 <long_to_date+0xa0>
movl   $0xffffffff,(%r14)
movl   $0xffffffff,(%r15)
movl   $0xffffffff,(%r12)
ff
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define void @long_to_date(i64 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [32 x i8]
%10 = alloca [32 x i8]
%11 = alloca [32 x i8]
store i64 %0, i64* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%13 = load i64, i64* %5
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = icmp ne i32 %16, 8
br i1 %17, label %18, label %22
18: ; preds = %4
%19 = load i32*, i32** %8
store i32 -1, i32* %19
%20 = load i32*, i32** %7
store i32 -1, i32* %20
%21 = load i32*, i32** %6
store i32 -1, i32* %21
br label %42
22: ; preds = %4
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds i8, i8* %24, i64 4
%26 = call i32 @strcpy(i8* %23, i8* %25)
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 2
%30 = call i32 @strcpy(i8* %27, i8* %29)
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 4
store i8 0, i8* %31
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 2
store i8 0, i8* %32
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%34 = call i32 @atoi(i8* %33)
%35 = load i32*, i32** %6
store i32 %34, i32* %35
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%37 = call i32 @atoi(i8* %36)
%38 = load i32*, i32** %7
store i32 %37, i32* %38
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%40 = call i32 @atoi(i8* %39)
%41 = load i32*, i32** %8
store i32 %40, i32* %41
br label %42
42: ; preds = %22, %18
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define void @long_to_date(i64 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%11 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%12 = call i32 @strlen(i8* %8)
%13 = icmp eq i32 %12, 8
br i1 %13, label %15, label %14
14: ; preds = %4
store i32 -1, i32* %3
store i32 -1, i32* %2
store i32 -1, i32* %1
br label %23
15: ; preds = %4
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 4
%17 = call i32 @strcpy(i8* %9, i8* %16)
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 2
%19 = call i32 @strcpy(i8* %10, i8* %18)
store i8 0, i8* %16
store i8 0, i8* %18
%20 = call i32 @atoi(i8* %8)
store i32 %20, i32* %1
%21 = call i32 @atoi(i8* %9)
store i32 %21, i32* %2
%22 = call i32 @atoi(i8* %10)
store i32 %22, i32* %3
br label %23
23: ; preds = %15, %14
ret void
}