#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 sscanf(char *, char *, int *, int *, int *);
int ymd_to_scalar(int, int, int);
int wg_strp_iso_date(void *db, char *inbuf) {
  int sres;
  int yr = 0;
  int mo = 0;
  int day = 0;
  int res;
  sres = sscanf(inbuf, "%4d-%2d-%2d", &yr, &mo, &day);
  if (sres < 3 || yr < 0 || mo < 1 || mo > 12 || day < 1 || day > 31)
    return -1;
  res = ymd_to_scalar(yr, mo, day);
  return res;
}


x86 assembly (clang, -O0):
<wg_strp_iso_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb0(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jl     11a0 <wg_strp_iso_date+0x80>
cmpl   $0x0,-0x20(%rbp)
jl     11a0 <wg_strp_iso_date+0x80>
cmpl   $0x1,-0x24(%rbp)
jl     11a0 <wg_strp_iso_date+0x80>
cmpl   $0xc,-0x24(%rbp)
jg     11a0 <wg_strp_iso_date+0x80>
cmpl   $0x1,-0x28(%rbp)
jl     11a0 <wg_strp_iso_date+0x80>
cmpl   $0x1f,-0x28(%rbp)
jle    11ac <wg_strp_iso_date+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <wg_strp_iso_date+0xa3>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1040 <ymd_to_scalar@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wg_strp_iso_date>:
sub    $0x18,%rsp
mov    %rsi,%rdi
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xeba(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x3,%ecx
jl     118d <wg_strp_iso_date+0x6d>
mov    0x14(%rsp),%edi
test   %edi,%edi
js     118d <wg_strp_iso_date+0x6d>
mov    0x10(%rsp),%esi
test   %esi,%esi
jle    118d <wg_strp_iso_date+0x6d>
cmp    $0xc,%esi
jg     118d <wg_strp_iso_date+0x6d>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    118d <wg_strp_iso_date+0x6d>
cmp    $0x1f,%edx
jg     118d <wg_strp_iso_date+0x6d>
call   1040 <ymd_to_scalar@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%4d-%2d-%2d\00"
define i32 @wg_strp_iso_date(i8* nocapture readnone %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%10 = icmp slt i32 %9, 3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
%13 = select i1 %10, i1 true, i1 %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 1
%16 = select i1 %13, i1 true, i1 %15
%17 = icmp sgt i32 %14, 12
%18 = select i1 %16, i1 true, i1 %17
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 1
%21 = select i1 %18, i1 true, i1 %20
%22 = icmp sgt i32 %19, 31
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %26, label %24
24: ; preds = %2
%25 = call i32 @ymd_to_scalar(i32 %11, i32 %14, i32 %19)
br label %26
26: ; preds = %2, %24
%27 = phi i32 [ %25, %24 ], [ -1, %2 ]
ret i32 %27
}