#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*/ isdigit(char);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int strlen(char *);
int Decode_date_mday(char *text, int flag) {
  int ret, i;
  for (i = 0; text[i] != 0; i++)
    if (!isdigit(text[i]))
      return (-1);
  if (strlen(text) > 2 || text[0] == 0)
    return (-2);
  sscanf(text, "%d", &ret);
  if (ret <= 0 || ret > 31)
    return (-2);
  return (ret);
}


x86 assembly (clang, -O0):
<Decode_date_mday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1194 <Decode_date_mday+0x64>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1181 <Decode_date_mday+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <Decode_date_mday+0xcc>
jmp    1186 <Decode_date_mday+0x56>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1146 <Decode_date_mday+0x16>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jg     11b6 <Decode_date_mday+0x86>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c2 <Decode_date_mday+0x92>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11fc <Decode_date_mday+0xcc>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
cmpl   $0x0,-0x18(%rbp)
jle    11ea <Decode_date_mday+0xba>
cmpl   $0x1f,-0x18(%rbp)
jle    11f6 <Decode_date_mday+0xc6>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11fc <Decode_date_mday+0xcc>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Decode_date_mday>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%al
test   %al,%al
je     1167 <Decode_date_mday+0x37>
lea    0x1(%r14),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11a9 <Decode_date_mday+0x79>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <Decode_date_mday+0x20>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    $0x2,%ecx
jg     11ae <Decode_date_mday+0x7e>
cmpb   $0x0,(%r14)
je     11ae <Decode_date_mday+0x7e>
lea    0xe78(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1050 <sscanf@plt>
mov    0x4(%rsp),%ecx
lea    -0x20(%rcx),%eax
cmp    $0xffffffe1,%eax
mov    $0xfffffffe,%eax
cmovae %ecx,%eax
jmp    11ae <Decode_date_mday+0x7e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @Decode_date_mday(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %17, label %11
7: ; preds = %11
%8 = getelementptr inbounds i8, i8* %0, i64 %16
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %2, %7
%12 = phi i64 [ %16, %7 ], [ 0, %2 ]
%13 = phi i8 [ %9, %7 ], [ %5, %2 ]
%14 = tail call i32 @isdigit(i8 signext %13)
%15 = icmp eq i32 %14, 0
%16 = add nuw i64 %12, 1
br i1 %15, label %29, label %7
17: ; preds = %7, %2
%18 = tail call i32 @strlen(i8* %0)
%19 = icmp sgt i32 %18, 2
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = load i8, i8* %0
%22 = icmp eq i8 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %3
%26 = add i32 %25, -32
%27 = icmp ult i32 %26, -31
%28 = select i1 %27, i32 -2, i32 %25
br label %29
29: ; preds = %11, %23, %17, %20
%30 = phi i32 [ -2, %20 ], [ -2, %17 ], [ %28, %23 ], [ -1, %11 ]
ret i32 %30
}