#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);
scalar_t__ matchtag(int, int, int);
int checktag(int tags[], int numtags, int exprtag) {
  int i;
  assert(tags != 0);
  assert(numtags > 0);
  for (i = 0; i < numtags; i++)
    if (matchtag(tags[i], exprtag, 1))
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<checktag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a9 <checktag+0x89>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1030 <matchtag@plt>
cmp    $0x0,%rax
je     1196 <checktag+0x76>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <checktag+0x90>
jmp    119b <checktag+0x7b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115c <checktag+0x3c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checktag>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r12
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14d,%r14d
setg   %dil
call   1040 <assert@plt>
test   %r14d,%r14d
jle    117f <checktag+0x5f>
mov    %r14d,%r14d
xor    %ebx,%ebx
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    (%r12,%rbx,4),%edi
mov    %r15d,%esi
mov    $0x1,%edx
call   1030 <matchtag@plt>
test   %rax,%rax
jne    1181 <checktag+0x61>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <checktag+0x40>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @checktag(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %6
%14 = icmp sgt i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
store i32 0, i32* %8
br label %17
17: ; preds = %32, %3
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i32*, i32** %5
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %7
%28 = call i64 @matchtag(i32 %26, i32 %27, i32 1)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %21
store i32 1, i32* %4
br label %36
31: ; preds = %21
br label %32
32: ; preds = %31
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %17
35: ; preds = %17
store i32 0, i32* %4
br label %36
36: ; preds = %35, %30
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @checktag(i32* %0, i32 %1, i32 %2) {
%4 = icmp ne i32* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %1, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
br i1 %7, label %10, label %21
10: ; preds = %3
%11 = zext i32 %1 to i64
br label %14
12: ; preds = %14
%13 = icmp eq i64 %20, %11
br i1 %13, label %21, label %14
14: ; preds = %10, %12
%15 = phi i64 [ 0, %10 ], [ %20, %12 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = tail call i64 @matchtag(i32 %17, i32 %2, i32 1)
%19 = icmp eq i64 %18, 0
%20 = add nuw nsw i64 %15, 1
br i1 %19, label %12, label %21
21: ; preds = %14, %12, %3
%22 = phi i32 [ 0, %3 ], [ 0, %12 ], [ 1, %14 ]
ret i32 %22
}