#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 */
void stub1(void *);
void stub2();
void iterateAndInbetween(void (*f)(void *), void (*g)(void), void **list) {
  if (list == NULL)
    return;
  void *l;
  int i = -1;
  while (true) {
    if ((l = list[++i]) == NULL)
      break;
    (*f)(l);
    if (list[i + 1] != NULL)
      (*g)();
  }
}


x86 assembly (clang, -O0):
<iterateAndInbetween>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1124 <iterateAndInbetween+0x24>
jmp    117c <iterateAndInbetween+0x7c>
movl   $0xffffffff,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1152 <iterateAndInbetween+0x52>
jmp    117c <iterateAndInbetween+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rdi
call   *%rax
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1177 <iterateAndInbetween+0x77>
call   *-0x10(%rbp)
jmp    112b <iterateAndInbetween+0x2b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterateAndInbetween>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     114e <iterateAndInbetween+0x4e>
mov    %rdx,%r12
mov    %rdi,%r15
mov    (%rdx),%rdi
test   %rdi,%rdi
je     114e <iterateAndInbetween+0x4e>
mov    %rsi,%r14
mov    $0x1,%ebx
jmp    113f <iterateAndInbetween+0x3f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
mov    (%r12,%rax,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
je     114e <iterateAndInbetween+0x4e>
call   *%r15
cmpq   $0x0,(%r12,%rbx,8)
je     1130 <iterateAndInbetween+0x30>
call   *%r14
jmp    1130 <iterateAndInbetween+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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