#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*/ assert(int);
int sscanf(char const *, char *, int *, char *, int *);
size_t strlen(char const *);
int chirp_ticket_isticketfilename(const char *ticket_filename,
                                  const char **digest) {
  int n1, n2;
  char buffer[((16 << 1)) + 1];
  if ((sscanf(ticket_filename,
              ".__"
              "ticket."
              "%n%32[0123456789abcdefABCDEF]%n",
              &n1, buffer, &n2) == 1) &&
      ((n2 - n1) == ((16 << 1))) && (strlen(ticket_filename) == (size_t)n2)) {
    assert(n1 > 0);
    *digest = ticket_filename + n1;
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<chirp_ticket_isticketfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rcx
lea    0xeb1(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%r8
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11b9 <chirp_ticket_isticketfilename+0x89>
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x20,%eax
jne    11b9 <chirp_ticket_isticketfilename+0x89>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
movslq -0x20(%rbp),%rcx
cmp    %rcx,%rax
jne    11b9 <chirp_ticket_isticketfilename+0x89>
cmpl   $0x0,-0x1c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rax
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c0 <chirp_ticket_isticketfilename+0x90>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chirp_ticket_isticketfilename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb7(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1050 <sscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
jne    11a4 <chirp_ticket_isticketfilename+0x74>
movslq 0xc(%rsp),%r12
mov    0x8(%rsp),%r15d
mov    %r12d,%eax
sub    %r15d,%eax
cmp    $0x20,%eax
jne    11a4 <chirp_ticket_isticketfilename+0x74>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %r12,%rax
jne    11a4 <chirp_ticket_isticketfilename+0x74>
xor    %edi,%edi
test   %r15d,%r15d
setg   %dil
call   1040 <assert@plt>
movslq 0x8(%rsp),%rax
add    %rax,%rbx
mov    %rbx,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c".__ticket.%n%32[0123456789abcdefABCDEF]%n\00"
define i32 @chirp_ticket_isticketfilename(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [33 x i8]
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = load i8*, i8** %4
%10 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 0
%11 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32* %6, i8* %10, i32* %7)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %34
13: ; preds = %2
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = sub nsw i32 %14, %15
%17 = icmp eq i32 %16, 32
br i1 %17, label %18, label %34
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = icmp eq i64 %20, %22
br i1 %23, label %24, label %34
24: ; preds = %18
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8**, i8*** %5
store i8* %32, i8** %33
store i32 1, i32* %3
br label %35
34: ; preds = %18, %13, %2
store i32 0, i32* %3
br label %35
35: ; preds = %34, %24
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [42 x i8] c".__ticket.%n%32[0123456789abcdefABCDEF]%n\00"
define i32 @chirp_ticket_isticketfilename(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [33 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [33 x i8], [33 x i8]* %5, i64 0, i64 0
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %8, i32* %4)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = sub nsw i32 %12, %13
%15 = icmp eq i32 %14, 32
br i1 %15, label %16, label %27
16: ; preds = %11
%17 = call i64 @strlen(i8* dereferenceable(1) %0)
%18 = sext i32 %12 to i64
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = icmp sgt i32 %13, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8* %26, i8** %1
br label %27
27: ; preds = %2, %11, %16, %20
%28 = phi i32 [ 1, %20 ], [ 0, %16 ], [ 0, %11 ], [ 0, %2 ]
ret i32 %28
}