#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 const general_field_type(char const *, int);
int general_field_next_terminate(const char *general_field, int i,
                                 const int general_field_len, int num,
                                 const int max_num, const int type) {
  if (i + max_num < general_field_len) {
    return 0;
  }
  for (; i < general_field_len; i++, num--) {
    if (general_field_type(general_field, i) != type) {
      return 0;
    }
  }
  return i == general_field_len && num <= 0;
}


x86 assembly (clang, -O0):
<general_field_next_terminate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1148 <general_field_next_terminate+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11bc <general_field_next_terminate+0xac>
jmp    114d <general_field_next_terminate+0x3d>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1196 <general_field_next_terminate+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <general_field_type@plt>
cmp    -0x24(%rbp),%eax
je     117a <general_field_next_terminate+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11bc <general_field_next_terminate+0xac>
jmp    117f <general_field_next_terminate+0x6f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    114d <general_field_next_terminate+0x3d>
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x25(%rbp)
jne    11b1 <general_field_next_terminate+0xa1>
cmpl   $0x0,-0x1c(%rbp)
setle  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<general_field_next_terminate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
add    %esi,%r8d
xor    %r15d,%r15d
cmp    %edx,%r8d
jl     1169 <general_field_next_terminate+0x59>
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%ebp
cmp    %edx,%esi
jge    1158 <general_field_next_terminate+0x48>
mov    %r9d,%r12d
mov    %rdi,%r13
add    %ebp,%r14d
sub    %ebx,%r14d
nopl   (%rax)
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <general_field_type@plt>
cmp    %r12d,%eax
jne    1169 <general_field_next_terminate+0x59>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1140 <general_field_next_terminate+0x30>
mov    %ebx,%ebp
cmp    %ebx,%ebp
sete   %al
test   %r14d,%r14d
setle  %cl
and    %al,%cl
movzbl %cl,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @general_field_next_terminate(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%14 = load i32, i32* %9
%15 = load i32, i32* %12
%16 = add nsw i32 %14, %15
%17 = load i32, i32* %10
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %6
store i32 0, i32* %7
br label %48
20: ; preds = %6
br label %21
21: ; preds = %33, %20
%22 = load i32, i32* %9
%23 = load i32, i32* %10
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = call i32 @general_field_type(i8* %26, i32 %27)
%29 = load i32, i32* %13
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 0, i32* %7
br label %48
32: ; preds = %25
br label %33
33: ; preds = %32
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
%36 = load i32, i32* %11
%37 = add nsw i32 %36, -1
store i32 %37, i32* %11
br label %21
38: ; preds = %21
%39 = load i32, i32* %9
%40 = load i32, i32* %10
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i32, i32* %11
%44 = icmp sle i32 %43, 0
br label %45
45: ; preds = %42, %38
%46 = phi i1 [ false, %38 ], [ %44, %42 ]
%47 = zext i1 %46 to i32
store i32 %47, i32* %7
br label %48
48: ; preds = %45, %31, %19
%49 = load i32, i32* %7
ret i32 %49
}

LLVM IR (-O2):
define i32 @general_field_next_terminate(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = add nsw i32 %4, %1
%8 = icmp slt i32 %7, %2
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = icmp slt i32 %1, %2
br i1 %10, label %11, label %21
11: ; preds = %9
%12 = add i32 %3, %1
%13 = sub i32 %12, %2
br label %14
14: ; preds = %11, %18
%15 = phi i32 [ %19, %18 ], [ %1, %11 ]
%16 = tail call i32 @general_field_type(i8* %0, i32 %15)
%17 = icmp eq i32 %16, %5
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = add i32 %15, 1
%20 = icmp eq i32 %19, %2
br i1 %20, label %21, label %14
21: ; preds = %18, %9
%22 = phi i32 [ %3, %9 ], [ %13, %18 ]
%23 = phi i32 [ %1, %9 ], [ %2, %18 ]
%24 = icmp eq i32 %23, %2
%25 = icmp slt i32 %22, 1
%26 = and i1 %24, %25
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %14, %6, %21
%29 = phi i32 [ %27, %21 ], [ 0, %6 ], [ 0, %14 ]
ret i32 %29
}