#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*/ free(char *);
scalar_t__ is_fac_branch(char *);
scalar_t__ is_fac_year(char *);
scalar_t__ is_serial_number(char *);
size_t len(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *to_upper(char *);
int verify_fn(char *fac_no) {
  char *fn = to_upper(fac_no);
  char year[3], branch[4], serial[4];
  size_t n = len(fn);
  if (n == 8) {
    strncpy(year, fn, 2);
    year[2] = '\0';
    strncpy(branch, &fn[2], 3);
    branch[3] = '\0';
    strncpy(serial, &fn[5], 3);
    serial[3] = '\0';
    if (is_fac_year(year) && is_fac_branch(branch) &&
        is_serial_number(serial)) {
      free(fn);
      return 1;
    }
  }
  free(fn);
  return 0;
}


x86 assembly (clang, -O0):
<verify_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <to_upper@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <len@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x8,-0x30(%rbp)
jne    123e <verify_fn+0xce>
lea    -0x1b(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1050 <strncpy@plt>
movb   $0x0,-0x19(%rbp)
lea    -0x1f(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x2,%rsi
mov    $0x3,%edx
call   1050 <strncpy@plt>
movb   $0x0,-0x1c(%rbp)
lea    -0x23(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x5,%rsi
mov    $0x3,%edx
call   1050 <strncpy@plt>
movb   $0x0,-0x20(%rbp)
lea    -0x1b(%rbp),%rdi
call   1080 <is_fac_year@plt>
cmp    $0x0,%rax
je     1239 <verify_fn+0xc9>
lea    -0x1f(%rbp),%rdi
call   1060 <is_fac_branch@plt>
cmp    $0x0,%rax
je     1239 <verify_fn+0xc9>
lea    -0x23(%rbp),%rdi
call   1070 <is_serial_number@plt>
cmp    $0x0,%rax
je     1239 <verify_fn+0xc9>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <verify_fn+0xde>
jmp    123e <verify_fn+0xce>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_fn>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
call   1090 <to_upper@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <len@plt>
cmp    $0x8,%rax
jne    1209 <verify_fn+0x99>
lea    0x15(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <strncpy@plt>
movb   $0x0,0x17(%rsp)
lea    0x2(%rbx),%rsi
lea    0x11(%rsp),%rdi
mov    $0x3,%edx
call   1050 <strncpy@plt>
movb   $0x0,0x14(%rsp)
mov    %rbx,%rsi
add    $0x5,%rsi
lea    0xd(%rsp),%rdi
mov    $0x3,%edx
call   1050 <strncpy@plt>
movb   $0x0,0x10(%rsp)
mov    %rbp,%rdi
call   1080 <is_fac_year@plt>
test   %rax,%rax
je     1209 <verify_fn+0x99>
lea    0x11(%rsp),%rdi
call   1060 <is_fac_branch@plt>
test   %rax,%rax
je     1209 <verify_fn+0x99>
lea    0xd(%rsp),%rdi
call   1070 <is_serial_number@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    120b <verify_fn+0x9b>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @verify_fn(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca [4 x i8]
%7 = alloca [4 x i8]
%8 = alloca i64
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @to_upper(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = call i64 @len(i8* %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = icmp eq i64 %13, 8
br i1 %14, label %15, label %45
15: ; preds = %1
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = call i32 @strncpy(i8* %16, i8* %17, i32 2)
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %19
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = call i32 @strncpy(i8* %20, i8* %22, i32 3)
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 0, i8* %24
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 5
%28 = call i32 @strncpy(i8* %25, i8* %27, i32 3)
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 3
store i8 0, i8* %29
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%31 = call i64 @is_fac_year(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %15
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%35 = call i64 @is_fac_branch(i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%39 = call i64 @is_serial_number(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = call i32 @free(i8* %42)
store i32 1, i32* %2
br label %48
44: ; preds = %37, %33, %15
br label %45
45: ; preds = %44, %1
%46 = load i8*, i8** %4
%47 = call i32 @free(i8* %46)
store i32 0, i32* %2
br label %48
48: ; preds = %45, %41
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
define i32 @verify_fn(i8* %0) {
%2 = alloca [3 x i8]
%3 = alloca [4 x i8]
%4 = alloca [4 x i8]
%5 = tail call i8* @to_upper(i8* %0)
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%9 = tail call i64 @len(i8* %5)
%10 = icmp eq i64 %9, 8
br i1 %10, label %11, label %28
11: ; preds = %1
%12 = call i32 @strncpy(i8* %6, i8* %5, i32 2)
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 0, i8* %13
%14 = getelementptr inbounds i8, i8* %5, i64 2
%15 = call i32 @strncpy(i8* %7, i8* %14, i32 3)
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 0, i8* %16
%17 = getelementptr inbounds i8, i8* %5, i64 5
%18 = call i32 @strncpy(i8* %8, i8* %17, i32 3)
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 0, i8* %19
%20 = call i64 @is_fac_year(i8* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %11
%23 = call i64 @is_fac_branch(i8* %7)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i64 @is_serial_number(i8* %8)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %11, %22, %25, %1
br label %29
29: ; preds = %25, %28
%30 = phi i32 [ 0, %28 ], [ 1, %25 ]
%31 = call i32 @free(i8* %5)
ret i32 %30
}