#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 */
struct eeprom_table {
  int dummy;
};

/* Variables and functions */
unsigned int epilogue(char *);
unsigned int prologue(char *);
int stage_wrapper(char *str,
                  void (*stage)(int device_fd,
                                struct eeprom_table *new_e2prom_tab_p,
                                int dump_mode),
                  void (*stage_dump)(struct eeprom_table *new_e2prom_tab_p),
                  int device_fd, struct eeprom_table *new_e2prom_tab_p,
                  int dump_mode) {
  unsigned int ret;
  if (dump_mode) {
    ret = epilogue(str);
    if (ret == 1)
      return 1;
  }
  while (1) {
    stage(device_fd, new_e2prom_tab_p, dump_mode);
  summary:
    ret = prologue(str);
    if (!ret)
      break;
    else if (ret == 2) {
      stage_dump(new_e2prom_tab_p);
      goto summary;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<stage_wrapper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1170 <stage_wrapper+0x50>
mov    -0x10(%rbp),%rdi
call   1030 <epilogue@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
jne    116b <stage_wrapper+0x4b>
movl   $0x1,-0x4(%rbp)
jmp    11ca <stage_wrapper+0xaa>
jmp    1170 <stage_wrapper+0x50>
jmp    1175 <stage_wrapper+0x55>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   *%rax
mov    -0x10(%rbp),%rdi
call   1040 <prologue@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    11a0 <stage_wrapper+0x80>
jmp    11c3 <stage_wrapper+0xa3>
cmpl   $0x2,-0x38(%rbp)
jne    11b9 <stage_wrapper+0x99>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rdi
call   *%rax
jmp    1185 <stage_wrapper+0x65>
jmp    11be <stage_wrapper+0x9e>
jmp    1175 <stage_wrapper+0x55>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stage_wrapper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbp
test   %r9d,%r9d
je     1156 <stage_wrapper+0x36>
mov    %rbp,%rdi
call   1030 <epilogue@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x1,%ecx
je     1194 <stage_wrapper+0x74>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   *%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1040 <prologue@plt>
cmp    $0x2,%eax
jne    1190 <stage_wrapper+0x70>
mov    %rbx,%rdi
call   *%r13
jmp    1170 <stage_wrapper+0x50>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%eax
jne    1156 <stage_wrapper+0x36>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.eeprom_table = type { i32 }
define i32 @stage_wrapper(i8* %0, void (i32, %struct.eeprom_table*, i32)* %1, void (%struct.eeprom_table*)* %2, i32 %3, %struct.eeprom_table* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca void (i32, %struct.eeprom_table*, i32)*
%10 = alloca void (%struct.eeprom_table*)*
%11 = alloca i32
%12 = alloca %struct.eeprom_table*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %8
store void (i32, %struct.eeprom_table*, i32)* %1, void (i32, %struct.eeprom_table*, i32)** %9
store void (%struct.eeprom_table*)* %2, void (%struct.eeprom_table*)** %10
store i32 %3, i32* %11
store %struct.eeprom_table* %4, %struct.eeprom_table** %12
store i32 %5, i32* %13
%15 = load i32, i32* %13
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %6
%18 = load i8*, i8** %8
%19 = call i32 @epilogue(i8* %18)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %7
br label %45
23: ; preds = %17
br label %24
24: ; preds = %23, %6
br label %25
25: ; preds = %24, %43
%26 = load void (i32, %struct.eeprom_table*, i32)*, void (i32, %struct.eeprom_table*, i32)** %9
%27 = load i32, i32* %11
%28 = load %struct.eeprom_table*, %struct.eeprom_table** %12
%29 = load i32, i32* %13
br label %30
30: ; preds = %39, %25
%31 = load i8*, i8** %8
%32 = call i32 @prologue(i8* %31)
store i32 %32, i32* %14
%33 = load i32, i32* %14
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %30
br label %44
36: ; preds = %30
%37 = load i32, i32* %14
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load void (%struct.eeprom_table*)*, void (%struct.eeprom_table*)** %10
%41 = load %struct.eeprom_table*, %struct.eeprom_table** %12
br label %30
42: ; preds = %36
br label %43
43: ; preds = %42
br label %25
44: ; preds = %35
store i32 0, i32* %7
br label %45
45: ; preds = %44, %22
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
%struct.eeprom_table = type { i32 }
define i32 @stage_wrapper(i8* %0, void (i32, %struct.eeprom_table*, i32)* nocapture %1, void (%struct.eeprom_table*)* nocapture %2, i32 %3, %struct.eeprom_table* %4, i32 %5) {
%7 = icmp eq i32 %5, 0
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call i32 @epilogue(i8* %0)
%10 = icmp eq i32 %9, 1
br i1 %10, label %16, label %11
11: ; preds = %8, %6
br label %12
12: ; preds = %13, %11
tail call void %1(i32 %3, %struct.eeprom_table* %4, i32 %5)
br label %13
13: ; preds = %15, %12
%14 = tail call i32 @prologue(i8* %0)
switch i32 %14, label %12 [
i32 0, label %16
i32 2, label %15
]
15: ; preds = %13
tail call void %2(%struct.eeprom_table* %4)
br label %13
16: ; preds = %13, %8
%17 = phi i32 [ 1, %8 ], [ %14, %13 ]
ret i32 %17
}