#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*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ get_fun_value(char const *, int *, int);
scalar_t__ get_fundef(char const *, int *, int, int *);
int /*<<< orphan*/ stderr;
int setup_functions(const char *buf, int bufsize) {
  int pc = 0;
  int current_fundef = 0;
  while (pc != bufsize) {
    if (get_fun_value(buf, &pc, bufsize)) {
      if (get_fundef(buf, &pc, bufsize, &current_fundef)) {
        fprintf(stderr, "Invalid function definition (function %d)\n",
                current_fundef);
        return 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<setup_functions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11bf <setup_functions+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1030 <get_fun_value@plt>
cmp    $0x0,%rax
je     11ba <setup_functions+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
call   1050 <get_fundef@plt>
cmp    $0x0,%rax
je     11b5 <setup_functions+0x85>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c6 <setup_functions+0x96>
jmp    11ba <setup_functions+0x8a>
jmp    114d <setup_functions+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_functions>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
xor    %r14d,%r14d
test   %esi,%esi
je     11bc <setup_functions+0x8c>
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
jmp    1176 <setup_functions+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %ebp,0xc(%rsp)
je     11bc <setup_functions+0x8c>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <get_fun_value@plt>
test   %rax,%rax
je     1170 <setup_functions+0x40>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r12,%rcx
call   1050 <get_fundef@plt>
test   %rax,%rax
je     1170 <setup_functions+0x40>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%edx
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Invalid function definition (function %d)\0A\00"
define i32 @setup_functions(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %27, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %5
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = call i64 @get_fun_value(i8* %13, i32* %6, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = call i64 @get_fundef(i8* %18, i32* %6, i32 %19, i32* %7)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i32, i32* %7
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %24)
store i32 1, i32* %3
br label %29
26: ; preds = %17
br label %27
27: ; preds = %26, %12
br label %8
28: ; preds = %8
store i32 0, i32* %3
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Invalid function definition (function %d)\0A\00"
define i32 @setup_functions(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = icmp eq i32 %1, 0
br i1 %7, label %21, label %8
8: ; preds = %2, %18
%9 = call i64 @get_fun_value(i8* %0, i32* %3, i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = call i64 @get_fundef(i8* %0, i32* %3, i32 %1, i32* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32, i32* %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %21
18: ; preds = %11, %8
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, %1
br i1 %20, label %21, label %8
21: ; preds = %18, %2, %14
%22 = phi i32 [ 1, %14 ], [ 0, %2 ], [ 0, %18 ]
ret i32 %22
}