#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 compile_next_buffered_pigsty_entry(char *, char **);
int compile_pigsty_buffer(const char *buffer) {
  int all_ok = 1;
  char *data = (char *)buffer;
  char *next_data = NULL;
  all_ok = compile_next_buffered_pigsty_entry(data, &next_data);
  while (all_ok && *next_data != 0) {
    data = next_data;
    all_ok = compile_next_buffered_pigsty_entry(data, &next_data);
  }
  return all_ok;
}


x86 assembly (clang, -O0):
<compile_pigsty_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <compile_next_buffered_pigsty_entry@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x21(%rbp)
je     1162 <compile_pigsty_buffer+0x52>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1172 <compile_pigsty_buffer+0x62>
jmp    118f <compile_pigsty_buffer+0x7f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <compile_next_buffered_pigsty_entry@plt>
mov    %eax,-0xc(%rbp)
jmp    1143 <compile_pigsty_buffer+0x33>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compile_pigsty_buffer>:
push   %rbp
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    %rsp,%rsi
call   1030 <compile_next_buffered_pigsty_entry@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1157 <compile_pigsty_buffer+0x47>
mov    (%rsp),%rdi
cmpb   $0x0,(%rdi)
je     1155 <compile_pigsty_buffer+0x45>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rsi
call   1030 <compile_next_buffered_pigsty_entry@plt>
test   %eax,%eax
je     1157 <compile_pigsty_buffer+0x47>
mov    (%rsp),%rdi
cmpb   $0x0,(%rdi)
jne    1140 <compile_pigsty_buffer+0x30>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @compile_pigsty_buffer(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i32 1, i32* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
store i8* null, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @compile_next_buffered_pigsty_entry(i8* %7, i8** %5)
store i32 %8, i32* %3
br label %9
9: ; preds = %19, %1
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %12, %9
%18 = phi i1 [ false, %9 ], [ %16, %12 ]
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = load i8*, i8** %5
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @compile_next_buffered_pigsty_entry(i8* %21, i8** %5)
store i32 %22, i32* %3
br label %9
23: ; preds = %17
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @compile_pigsty_buffer(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = call i32 @compile_next_buffered_pigsty_entry(i8* %0, i8** %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %18, label %14
10: ; preds = %14
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %6, %10
%15 = phi i8* [ %11, %10 ], [ %7, %6 ]
%16 = call i32 @compile_next_buffered_pigsty_entry(i8* %15, i8** %2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %14, %10, %6, %1
%19 = phi i32 [ 0, %1 ], [ %4, %6 ], [ %16, %10 ], [ 0, %14 ]
ret i32 %19
}