#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*/ piece(char *, char, char *, int);
int sfwmd_ora_month2integer(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int);
char *sfwmd_to_yyyy_mm_dd(char *d, char *s) {
  int mm_int;
  char yyyy[128], mon[128], dd[128];
  if (!piece(dd, '-', s, 0))
    return (char *)0;
  if (!piece(mon, '-', s, 1))
    return (char *)0;
  if (!piece(yyyy, '-', s, 2))
    return (char *)0;
  mm_int = sfwmd_ora_month2integer(mon);
  if (mm_int < 0)
    return (char *)0;
  sprintf(d, "%s-%02d-%02d", yyyy, mm_int + 1, atoi(dd));
  return d;
}


x86 assembly (clang, -O0):
<sfwmd_to_yyyy_mm_dd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2d,%esi
xor    %ecx,%ecx
call   1050 <piece@plt>
cmp    $0x0,%eax
jne    1180 <sfwmd_to_yyyy_mm_dd+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1262 <sfwmd_to_yyyy_mm_dd+0x122>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2d,%esi
mov    $0x1,%ecx
call   1050 <piece@plt>
cmp    $0x0,%eax
jne    11b0 <sfwmd_to_yyyy_mm_dd+0x70>
movq   $0x0,-0x8(%rbp)
jmp    1262 <sfwmd_to_yyyy_mm_dd+0x122>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2d,%esi
mov    $0x2,%ecx
call   1050 <piece@plt>
cmp    $0x0,%eax
jne    11e0 <sfwmd_to_yyyy_mm_dd+0xa0>
movq   $0x0,-0x8(%rbp)
jmp    1262 <sfwmd_to_yyyy_mm_dd+0x122>
lea    -0x120(%rbp),%rdi
call   1060 <sfwmd_ora_month2integer@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1206 <sfwmd_to_yyyy_mm_dd+0xc6>
movq   $0x0,-0x8(%rbp)
jmp    1262 <sfwmd_to_yyyy_mm_dd+0x122>
mov    -0x10(%rbp),%rax
mov    %rax,-0x1b8(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x1b0(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
lea    -0x1a0(%rbp),%rdi
call   1030 <atoi@plt>
mov    -0x1b8(%rbp),%rdi
mov    -0x1b0(%rbp),%rdx
mov    -0x1a4(%rbp),%ecx
mov    %eax,%r8d
lea    0xdab(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sfwmd_to_yyyy_mm_dd>:
push   %r14
push   %rbx
sub    $0x188,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x2d,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1050 <piece@plt>
test   %eax,%eax
je     11de <sfwmd_to_yyyy_mm_dd+0x9e>
lea    0x80(%rsp),%rdi
mov    $0x2d,%esi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1050 <piece@plt>
test   %eax,%eax
je     11de <sfwmd_to_yyyy_mm_dd+0x9e>
lea    0x100(%rsp),%rdi
mov    $0x2d,%esi
mov    %rbx,%rdx
mov    $0x2,%ecx
call   1050 <piece@plt>
test   %eax,%eax
je     11de <sfwmd_to_yyyy_mm_dd+0x9e>
lea    0x80(%rsp),%rdi
call   1060 <sfwmd_ora_month2integer@plt>
test   %eax,%eax
js     11de <sfwmd_to_yyyy_mm_dd+0x9e>
mov    %eax,%ebx
add    $0x1,%ebx
mov    %rsp,%rdi
call   1030 <atoi@plt>
lea    0xe39(%rip),%rsi
lea    0x100(%rsp),%rdx
mov    %r14,%rdi
mov    %ebx,%ecx
mov    %eax,%r8d
call   1040 <sprintf@plt>
jmp    11e1 <sfwmd_to_yyyy_mm_dd+0xa1>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x188,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"%s-%02d-%02d\00"
define i8* @sfwmd_to_yyyy_mm_dd(i8* writeonly %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = call i32 @piece(i8* %8, i8 signext 45, i8* %1, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %2
%12 = call i32 @piece(i8* %7, i8 signext 45, i8* %1, i32 1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %11
%15 = call i32 @piece(i8* %6, i8 signext 45, i8* %1, i32 2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = call i32 @sfwmd_ora_month2integer(i8* %7)
%19 = icmp slt i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = add nuw nsw i32 %18, 1
%22 = call i32 @atoi(i8* %8)
%23 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %21, i32 %22)
br label %24
24: ; preds = %17, %14, %11, %2, %20
%25 = phi i8* [ %0, %20 ], [ null, %2 ], [ null, %11 ], [ null, %14 ], [ null, %17 ]
ret i8* %25
}