#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*/ printf(char *, char *, long);
long stub1(char *, long, long);
int print_checks(char *buffer, long int buff_size, char *msg, int honor_msg,
                 long int (*fp)(char *, long int, long int)) {
  long int x = 0, offset = 0;
  while (x < buff_size) {
    x = (*fp)(buffer, buff_size, offset);
    if (x < 0)
      goto out;
    if (honor_msg)
      printf("- %s %ld.\n", msg, x);
    offset = x + 1;
  }
out:
  return 0;
}


x86 assembly (clang, -O0):
<print_checks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    119e <print_checks+0x8e>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   *%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    116f <print_checks+0x5f>
jmp    11a3 <print_checks+0x93>
cmpl   $0x0,-0x1c(%rbp)
je     118d <print_checks+0x7d>
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    113b <print_checks+0x2b>
jmp    11a3 <print_checks+0x93>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_checks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
jle    1173 <print_checks+0x63>
mov    %r8,%r12
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %edx,%edx
jmp    1149 <print_checks+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%r13),%rdx
cmp    %rbp,%r13
jge    1173 <print_checks+0x63>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   *%r12
test   %rax,%rax
js     1173 <print_checks+0x63>
mov    %rax,%r13
test   %r15d,%r15d
je     1140 <print_checks+0x30>
lea    0xe9a(%rip),%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <printf@plt>
jmp    1140 <print_checks+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"- %s %ld.\0A\00"
define i32 @print_checks(i8* %0, i64 %1, i8* %2, i32 %3, i64 (i8*, i64, i64)* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64 (i8*, i64, i64)*
%11 = alloca i64
%12 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i64 (i8*, i64, i64)* %4, i64 (i8*, i64, i64)** %10
store i64 0, i64* %11
store i64 0, i64* %12
br label %13
13: ; preds = %33, %5
%14 = load i64, i64* %11
%15 = load i64, i64* %7
%16 = icmp slt i64 %14, %15
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = load i64 (i8*, i64, i64)*, i64 (i8*, i64, i64)** %10
%19 = load i8*, i8** %6
%20 = load i64, i64* %7
%21 = load i64, i64* %12
%22 = call i64 %18(i8* %19, i64 %20, i64 %21)
store i64 %22, i64* %11
%23 = load i64, i64* %11
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
br label %37
26: ; preds = %17
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i8*, i8** %8
%31 = load i64, i64* %11
%32 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %30, i64 %31)
br label %33
33: ; preds = %29, %26
%34 = load i64, i64* %11
%35 = add nsw i64 %34, 1
store i64 %35, i64* %12
br label %13
36: ; preds = %13
br label %37
37: ; preds = %36, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"- %s %ld.\0A\00"
define i32 @print_checks(i8* %0, i64 %1, i8* %2, i32 %3, i64 (i8*, i64, i64)* nocapture %4) {
%6 = icmp sgt i64 %1, 0
br i1 %6, label %7, label %19
7: ; preds = %5
%8 = icmp eq i32 %3, 0
br label %9
9: ; preds = %7, %16
%10 = phi i64 [ 0, %7 ], [ %17, %16 ]
%11 = tail call i64 %4(i8* %0, i64 %1, i64 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %9
br i1 %8, label %16, label %14
14: ; preds = %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2, i64 %11)
br label %16
16: ; preds = %14, %13
%17 = add nuw nsw i64 %11, 1
%18 = icmp slt i64 %11, %1
br i1 %18, label %9, label %19
19: ; preds = %9, %16, %5
ret i32 0
}