#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  scalar_t__ rm_so;
};
typedef TYPE_1__ regmatch_t;

/* Variables and functions */
int regex_iterate(regmatch_t matches[], char string[], int max, void *dspace[],
                  void (*each_do)(regmatch_t, char *, int, void **)) {
  int i, total = 0;
  for (i = 0; i < max; i++) {
    if (matches[i].rm_so > 0) {
      total++;
      each_do(matches[i], string, max, dspace);
    }
  }
  return total;
}


x86 assembly (clang, -O0):
<regex_iterate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1181 <regex_iterate+0x81>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jle    116e <regex_iterate+0x6e>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%r8
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    (%rdi,%r8,8),%rdi
call   *%rax
jmp    1173 <regex_iterate+0x73>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1129 <regex_iterate+0x29>
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regex_iterate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,0x8(%rsp)
test   %edx,%edx
jle    1156 <regex_iterate+0x56>
mov    %edx,%r13d
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %edx,%r14d
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1139 <regex_iterate+0x39>
nop
add    $0x1,%r15
cmp    %r15,%r14
je     1158 <regex_iterate+0x58>
mov    (%rbx,%r15,8),%rdi
test   %rdi,%rdi
jle    1130 <regex_iterate+0x30>
add    $0x1,%ebp
mov    %r12,%rsi
mov    %r13d,%edx
mov    0x8(%rsp),%rcx
call   *0x10(%rsp)
jmp    1130 <regex_iterate+0x30>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64 }
define i32 @regex_iterate(%struct.TYPE_5__* %0, i8* %1, i32 %2, i8** %3, void (i64, i8*, i32, i8**)* %4) {
%6 = alloca %struct.TYPE_5__*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca void (i64, i8*, i32, i8**)*
%11 = alloca i32
%12 = alloca i32
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
store void (i64, i8*, i32, i8**)* %4, void (i64, i8*, i32, i8**)** %10
store i32 0, i32* %12
store i32 0, i32* %11
br label %13
13: ; preds = %39, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = load %struct.TYPE_5__*, %struct.TYPE_5__** %6
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %18, i64 %20
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %17
%26 = load i32, i32* %12
%27 = add nsw i32 %26, 1
store i32 %27, i32* %12
%28 = load void (i64, i8*, i32, i8**)*, void (i64, i8*, i32, i8**)** %10
%29 = load %struct.TYPE_5__*, %struct.TYPE_5__** %6
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %29, i64 %31
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = load i8**, i8*** %9
%36 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %32, i32 0, i32 0
%37 = load i64, i64* %36
br label %38
38: ; preds = %25, %17
br label %39
39: ; preds = %38
%40 = load i32, i32* %11
%41 = add nsw i32 %40, 1
store i32 %41, i32* %11
br label %13
42: ; preds = %13
%43 = load i32, i32* %12
ret i32 %43
}

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