#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 strlen(char *);
int forEachCharacter(char *input, int (*function)(char input)) {
  if (!input || !function)
    return 0;
  int i;
  for (i = 0; i < strlen(input); i++) {
    int output = function(input[i]);
    if (output)
      return output;
  }
  return 0;
}


x86 assembly (clang, -O0):
<forEachCharacter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <forEachCharacter+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1142 <forEachCharacter+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <forEachCharacter+0x99>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11a2 <forEachCharacter+0x92>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%edi
call   *%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     118f <forEachCharacter+0x7f>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <forEachCharacter+0x99>
jmp    1194 <forEachCharacter+0x84>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <forEachCharacter+0x39>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forEachCharacter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1165 <forEachCharacter+0x55>
mov    %rsi,%r14
test   %rsi,%rsi
je     1165 <forEachCharacter+0x55>
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1165 <forEachCharacter+0x55>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%edi
call   *%r14
test   %eax,%eax
jne    1163 <forEachCharacter+0x53>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <forEachCharacter+0x30>
xor    %ebp,%ebp
jmp    1165 <forEachCharacter+0x55>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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