#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*/ exit(int);
int is_pattern(int);
int is_pattern_naive(int);
int /*<<< orphan*/ printf(char *, int, ...);
void verify() {
  for (int i = 0; i < 65536; i++) {
    int expected = is_pattern_naive(i);
    int result = is_pattern(i);
    if (expected != result) {
      printf("failed for %04x: result %d, expected %d\n", i, result, expected);
      exit(1);
    }
    if (result) {
      printf("pattern: %04x\n", i);
    }
  }
}


x86 assembly (clang, -O0):
<verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x10000,-0x4(%rbp)
jge    11cd <verify+0x8d>
mov    -0x4(%rbp),%edi
call   1040 <is_pattern_naive@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <is_pattern@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     119f <verify+0x5f>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
je     11ba <verify+0x7a>
mov    -0x4(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <verify+0x7f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114f <verify+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify>:
push   %rbp
push   %r14
push   %rbx
lea    0xede(%rip),%r14
xor    %ebx,%ebx
jmp    115b <verify+0x1b>
nop
add    $0x1,%ebx
cmp    $0x10000,%ebx
je     1181 <verify+0x41>
mov    %ebx,%edi
call   1040 <is_pattern_naive@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <is_pattern@plt>
cmp    %eax,%ebp
jne    1186 <verify+0x46>
test   %ebp,%ebp
je     1150 <verify+0x10>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1150 <verify+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe73(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"failed for %04x: result %d, expected %d\0A\00"
@.str.1 = [15 x i8] c"pattern: %04x\0A\00"
define void @verify() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %28, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 65536
br i1 %6, label %7, label %31
7: ; preds = %4
%8 = load i32, i32* %1
%9 = call i32 @is_pattern_naive(i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %1
%11 = call i32 @is_pattern(i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %7
%16 = load i32, i32* %1
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %7
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %1
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27
%29 = load i32, i32* %1
%30 = add nsw i32 %29, 1
store i32 %30, i32* %1
br label %4
31: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"failed for %04x: result %d, expected %d\0A\00"
@.str.1 = [15 x i8] c"pattern: %04x\0A\00"
define void @verify() {
br label %2
1: ; preds = %14
ret void
2: ; preds = %0, %14
%3 = phi i32 [ 0, %0 ], [ %15, %14 ]
%4 = tail call i32 @is_pattern_naive(i32 %3)
%5 = tail call i32 @is_pattern(i32 %3)
%6 = icmp eq i32 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %5, i32 %4)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = icmp eq i32 %4, 0
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %3)
br label %14
14: ; preds = %12, %10
%15 = add nuw nsw i32 %3, 1
%16 = icmp eq i32 %15, 65536
br i1 %16, label %1, label %2
}