#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__ elem_segment();
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_element() {
  unsigned long off0, off1;
  unsigned long len;
  long delta = 0;
  len = mgetsize(&off0, &off1);
  if (len) {
    unsigned long count;
    msynch();
    mputuleb128(count = mgetuleb128());
    delta += msynch();
    while (count--)
      delta += elem_segment();
    delta += msetsize(off0, off1, delta);
  } else {
    delta += msetsize(off0, off1, delta);
    delta += msynch();
  }
  return delta;
}


x86 assembly (clang, -O0):
<section_element>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x20(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <mgetsize@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1200 <section_element+0xa0>
mov    $0x0,%al
call   1080 <msynch@plt>
mov    $0x0,%al
call   1060 <mgetuleb128@plt>
mov    %rax,%rdi
mov    %rdi,-0x28(%rbp)
call   1070 <mputuleb128@plt>
mov    $0x0,%al
call   1080 <msynch@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    $0x0,%rax
je     11e2 <section_element+0x82>
mov    $0x0,%al
call   1030 <elem_segment@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11b5 <section_element+0x55>
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    1228 <section_element+0xc8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <msetsize@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1080 <msynch@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<section_element>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <mgetsize@plt>
test   %rax,%rax
je     11d7 <section_element+0x77>
xor    %eax,%eax
call   1080 <msynch@plt>
xor    %eax,%eax
call   1060 <mgetuleb128@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <mputuleb128@plt>
xor    %eax,%eax
call   1080 <msynch@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     11c0 <section_element+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <elem_segment@plt>
add    %rax,%r14
add    $0xffffffffffffffff,%rbx
jne    11b0 <section_element+0x50>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %r14,%rdx
call   1050 <msetsize@plt>
add    %r14,%rax
jmp    11f5 <section_element+0x95>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <msetsize@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <msynch@plt>
add    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i64 @section_element() {
%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
br i1 %6, label %26, label %7
7: ; preds = %0
%8 = call i64 (...) @msynch()
%9 = call i64 (...) @mgetuleb128()
%10 = call i32 @mputuleb128(i64 %9)
%11 = call i64 (...) @msynch()
%12 = icmp eq i64 %9, 0
br i1 %12, label %20, label %13
13: ; preds = %7, %13
%14 = phi i64 [ %16, %13 ], [ %9, %7 ]
%15 = phi i64 [ %18, %13 ], [ %11, %7 ]
%16 = add i64 %14, -1
%17 = call i64 (...) @elem_segment()
%18 = add nsw i64 %17, %15
%19 = icmp eq i64 %16, 0
br i1 %19, label %20, label %13
20: ; preds = %13, %7
%21 = phi i64 [ %11, %7 ], [ %18, %13 ]
%22 = load i64, i64* %1
%23 = load i64, i64* %2
%24 = call i64 @msetsize(i64 %22, i64 %23, i64 %21)
%25 = add nsw i64 %24, %21
br label %32
26: ; preds = %0
%27 = load i64, i64* %1
%28 = load i64, i64* %2
%29 = call i64 @msetsize(i64 %27, i64 %28, i64 0)
%30 = call i64 (...) @msynch()
%31 = add nsw i64 %30, %29
br label %32
32: ; preds = %26, %20
%33 = phi i64 [ %25, %20 ], [ %31, %26 ]
ret i64 %33
}