#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 */
typedef int /*<<< orphan*/ line;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int sscanf(char *, char *, int *, ...);
int /*<<< orphan*/ stdin;
void testscanf() {
  int day, month, year;
  char monthname[20];
  char line[20];
  while (fgets(line, sizeof(line), stdin) > 0) {
    if (sscanf(line, "%d %s %d", &day, monthname, &year) == 3)
      printf("valid: %s\n", line);
    else if (sscanf(line, "%d/%d/%d", &month, &day, &year) == 3)
      printf("valid: %s\n", line);
    else
      printf("invalid: %s\n", line);
  }
}


x86 assembly (clang, -O0):
<testscanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x40(%rbp),%rdi
mov    0x2ea5(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jle    11eb <testscanf+0xbb>
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rcx
lea    0xe98(%rip),%rsi
lea    -0x4(%rbp),%rdx
lea    -0xc(%rbp),%r8
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    1195 <testscanf+0x65>
lea    -0x40(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
jmp    11e6 <testscanf+0xb6>
lea    -0x40(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0x4(%rbp),%rcx
lea    -0xc(%rbp),%r8
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    11d1 <testscanf+0xa1>
lea    -0x40(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
jmp    11e1 <testscanf+0xb1>
lea    -0x40(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    11e6 <testscanf+0xb6>
jmp    1138 <testscanf+0x8>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testscanf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2ea3(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x14,%esi
call   1040 <fgets@plt>
test   %rax,%rax
jle    11fe <testscanf+0xce>
lea    0xe9a(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r15
lea    0x30(%rsp),%r12
lea    0x4(%rsp),%r13
lea    0xe93(%rip),%rbp
jmp    11b3 <testscanf+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1040 <fgets@plt>
test   %rax,%rax
jle    11fe <testscanf+0xce>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbp,%rdi
cmp    $0x3,%eax
je     1190 <testscanf+0x60>
mov    %rbx,%rdi
lea    0xe2e(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r15,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbp,%rdi
cmp    $0x3,%eax
je     1190 <testscanf+0x60>
lea    0xe16(%rip),%rdi
jmp    1190 <testscanf+0x60>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [9 x i8] c"%d %s %d\00"
@.str.1 = [11 x i8] c"valid: %s\0A\00"
@.str.2 = [9 x i8] c"%d/%d/%d\00"
@.str.3 = [13 x i8] c"invalid: %s\0A\00"
define void @testscanf() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
br label %6
6: ; preds = %30, %0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i64 @fgets(i8* %7, i32 20, i32 %8)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %6
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%14 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i8* %13, i32* %3)
%15 = icmp eq i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %30
19: ; preds = %11
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%21 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %1, i32* %3)
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %29
26: ; preds = %19
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %29, %16
br label %6
31: ; preds = %6
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [9 x i8] c"%d %s %d\00"
@.str.1 = [11 x i8] c"valid: %s\0A\00"
@.str.2 = [9 x i8] c"%d/%d/%d\00"
@.str.3 = [13 x i8] c"invalid: %s\0A\00"
define void @testscanf() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i64 @fgets(i8* %10, i32 20, i32 %11)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %0, %21
%15 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i8* %9, i32* %3)
%16 = icmp eq i32 %15, 3
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %1, i32* %3)
%19 = icmp eq i32 %18, 3
%20 = select i1 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0)
br label %21
21: ; preds = %17, %14
%22 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %14 ], [ %20, %17 ]
%23 = call i32 @printf(i8* %22, i8* %10)
%24 = load i32, i32* @stdin
%25 = call i64 @fgets(i8* %10, i32 20, i32 %24)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %14, label %27
27: ; preds = %21, %0
ret void
}