#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 */
scalar_t__ function_body(int /*<<< orphan*/);
unsigned long mgetsize(unsigned long *, unsigned long *);
unsigned long mgetuleb128();
int /*<<< orphan*/ mputuleb128(unsigned long);
scalar_t__ msetsize(unsigned long, unsigned long, long);
scalar_t__ msynch();
long section_code() {
  unsigned long off0, off1;
  unsigned long len;
  long delta = 0;
  unsigned long index = 0;
  len = mgetsize(&off0, &off1);
  if (len) {
    unsigned long count;
    msynch();
    mputuleb128(count = mgetuleb128());
    delta += msynch();
    while (count--)
      delta += function_body(index++);
    delta += msetsize(off0, off1, delta);
  } else {
    msynch();
  }
  return delta;
}


x86 assembly (clang, -O0):
<section_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <mgetsize@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1217 <section_code+0xb7>
mov    $0x0,%al
call   1080 <msynch@plt>
mov    $0x0,%al
call   1060 <mgetuleb128@plt>
mov    %rax,%rdi
mov    %rdi,-0x30(%rbp)
call   1070 <mputuleb128@plt>
mov    $0x0,%al
call   1080 <msynch@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
cmp    $0x0,%rax
je     11f9 <section_code+0x99>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    %eax,%edi
call   1030 <function_body@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11bd <section_code+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <msetsize@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    121e <section_code+0xbe>
mov    $0x0,%al
call   1080 <msynch@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<section_code>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <mgetsize@plt>
mov    %rax,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1080 <msynch@plt>
test   %rbx,%rbx
je     11db <section_code+0x7b>
xor    %eax,%eax
call   1060 <mgetuleb128@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <mputuleb128@plt>
xor    %eax,%eax
call   1080 <msynch@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11c4 <section_code+0x64>
xor    %edi,%edi
nopl   0x0(%rax,%rax,1)
lea    0x1(%rdi),%r15
call   1030 <function_body@plt>
add    %rax,%rbx
mov    %r15,%rdi
cmp    %r15,%r14
jne    11b0 <section_code+0x50>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    %rbx,%rdx
call   1050 <msetsize@plt>
mov    %rax,%r14
add    %rbx,%r14
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @section_code() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 0, i64* %4
store i64 0, i64* %5
%7 = call i64 @mgetsize(i64* %1, i64* %2)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %35
10: ; preds = %0
%11 = call i64 (...) @msynch()
%12 = call i64 (...) @mgetuleb128()
store i64 %12, i64* %6
%13 = call i32 @mputuleb128(i64 %12)
%14 = call i64 (...) @msynch()
%15 = load i64, i64* %4
%16 = add nsw i64 %15, %14
store i64 %16, i64* %4
br label %17
17: ; preds = %21, %10
%18 = load i64, i64* %6
%19 = add i64 %18, -1
store i64 %19, i64* %6
%20 = icmp ne i64 %18, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i64, i64* %5
%23 = add i64 %22, 1
store i64 %23, i64* %5
%24 = trunc i64 %22 to i32
%25 = call i64 @function_body(i32 %24)
%26 = load i64, i64* %4
%27 = add nsw i64 %26, %25
store i64 %27, i64* %4
br label %17
28: ; preds = %17
%29 = load i64, i64* %1
%30 = load i64, i64* %2
%31 = load i64, i64* %4
%32 = call i64 @msetsize(i64 %29, i64 %30, i64 %31)
%33 = load i64, i64* %4
%34 = add nsw i64 %33, %32
store i64 %34, i64* %4
br label %37
35: ; preds = %0
%36 = call i64 (...) @msynch()
br label %37
37: ; preds = %35, %28
%38 = load i64, i64* %4
ret i64 %38
}

LLVM IR (-O2):
define i64 @section_code() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i64 @mgetsize(i64* %1, i64* %2)
%6 = icmp eq i64 %5, 0
%7 = call i64 (...) @msynch()
br i1 %6, label %29, label %8
8: ; preds = %0
%9 = call i64 (...) @mgetuleb128()
%10 = call i32 @mputuleb128(i64 %9)
%11 = call i64 (...) @msynch()
%12 = icmp eq i64 %9, 0
br i1 %12, label %23, label %13
13: ; preds = %8, %13
%14 = phi i64 [ %17, %13 ], [ %9, %8 ]
%15 = phi i64 [ %18, %13 ], [ 0, %8 ]
%16 = phi i64 [ %21, %13 ], [ %11, %8 ]
%17 = add i64 %14, -1
%18 = add nuw i64 %15, 1
%19 = trunc i64 %15 to i32
%20 = call i64 @function_body(i32 %19)
%21 = add nsw i64 %20, %16
%22 = icmp eq i64 %17, 0
br i1 %22, label %23, label %13
23: ; preds = %13, %8
%24 = phi i64 [ %11, %8 ], [ %21, %13 ]
%25 = load i64, i64* %1
%26 = load i64, i64* %2
%27 = call i64 @msetsize(i64 %25, i64 %26, i64 %24)
%28 = add nsw i64 %27, %24
br label %29
29: ; preds = %0, %23
%30 = phi i64 [ %28, %23 ], [ 0, %0 ]
ret i64 %30
}