#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 /*<<< orphan*/ ffpmsg(char *);
scalar_t__ ffverifydate(int, int, int, int *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int ffdt2s(int year, int month, int day, char *datestr, int *status) {
  if (*status > 0)
    return (*status);
  *datestr = '\0';
  if (ffverifydate(year, month, day, status) > 0) {
    ffpmsg("invalid date (ffdt2s)");
    return (*status);
  }
  if (year >= 1900 && year <= 1998)
    sprintf(datestr, "%.2d/%.2d/%.2d", day, month, year - 1900);
  else
    sprintf(datestr, "%.4d-%.2d-%.2d", year, month, day);
  return (*status);
}


x86 assembly (clang, -O0):
<ffdt2s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    1164 <ffdt2s+0x34>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <ffdt2s+0xd4>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <ffverifydate@plt>
cmp    $0x0,%rax
jle    11a1 <ffdt2s+0x71>
lea    0xe72(%rip),%rdi
call   1040 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <ffdt2s+0xd4>
cmpl   $0x76c,-0x8(%rbp)
jl     11e1 <ffdt2s+0xb1>
cmpl   $0x7ce,-0x8(%rbp)
jg     11e1 <ffdt2s+0xb1>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%r8d
sub    $0x76c,%r8d
lea    0xe3f(%rip),%rsi
call   1050 <sprintf@plt>
jmp    11fb <ffdt2s+0xcb>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe2f(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffdt2s>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%r8),%eax
test   %eax,%eax
jg     11a3 <ffdt2s+0x73>
mov    %r8,%rbx
mov    %rcx,%r12
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebp
movb   $0x0,(%rcx)
mov    %r8,%rcx
call   1030 <ffverifydate@plt>
test   %rax,%rax
jle    116b <ffdt2s+0x3b>
lea    0xe9c(%rip),%rdi
call   1040 <ffpmsg@plt>
jmp    11a1 <ffdt2s+0x71>
lea    -0x76c(%rbp),%r8d
cmp    $0x62,%r8d
ja     118a <ffdt2s+0x5a>
lea    0xe97(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
jmp    119c <ffdt2s+0x6c>
lea    0xe94(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1050 <sprintf@plt>
mov    (%rbx),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"invalid date (ffdt2s)\00"
@.str.1 = [15 x i8] c"%.2d/%.2d/%.2d\00"
@.str.2 = [15 x i8] c"%.4d-%.2d-%.2d\00"
define i32 @ffdt2s(i32 %0, i32 %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
%12 = load i32*, i32** %11
%13 = load i32, i32* %12
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i32*, i32** %11
%17 = load i32, i32* %16
store i32 %17, i32* %6
br label %52
18: ; preds = %5
%19 = load i8*, i8** %10
store i8 0, i8* %19
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = load i32*, i32** %11
%24 = call i64 @ffverifydate(i32 %20, i32 %21, i32 %22, i32* %23)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = call i32 @ffpmsg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%28 = load i32*, i32** %11
%29 = load i32, i32* %28
store i32 %29, i32* %6
br label %52
30: ; preds = %18
%31 = load i32, i32* %7
%32 = icmp sge i32 %31, 1900
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = load i32, i32* %7
%35 = icmp sle i32 %34, 1998
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i8*, i8** %10
%38 = load i32, i32* %9
%39 = load i32, i32* %8
%40 = load i32, i32* %7
%41 = sub nsw i32 %40, 1900
%42 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39, i32 %41)
br label %49
43: ; preds = %33, %30
%44 = load i8*, i8** %10
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %46, i32 %47)
br label %49
49: ; preds = %43, %36
%50 = load i32*, i32** %11
%51 = load i32, i32* %50
store i32 %51, i32* %6
br label %52
52: ; preds = %49, %26, %15
%53 = load i32, i32* %6
ret i32 %53
}

LLVM IR (-O2):
@.str = [22 x i8] c"invalid date (ffdt2s)\00"
@.str.1 = [15 x i8] c"%.2d/%.2d/%.2d\00"
@.str.2 = [15 x i8] c"%.4d-%.2d-%.2d\00"
define i32 @ffdt2s(i32 %0, i32 %1, i32 %2, i8* nocapture writeonly %3, i32* %4) {
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %5
store i8 0, i8* %3
%9 = tail call i64 @ffverifydate(i32 %0, i32 %1, i32 %2, i32* %4)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %20
13: ; preds = %8
%14 = add i32 %0, -1900
%15 = icmp ult i32 %14, 99
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %1, i32 %14)
br label %20
18: ; preds = %13
%19 = tail call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
br label %20
20: ; preds = %16, %18, %11
%21 = load i32, i32* %4
br label %22
22: ; preds = %20, %5
%23 = phi i32 [ %6, %5 ], [ %21, %20 ]
ret i32 %23
}