#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ ts_get_unitstart(int *);
int *ts_payload(int *);
uint8_t *ts_next_section(uint8_t *p_ts) {
  uint8_t *p_payload;
  if (!ts_get_unitstart(p_ts))
    return p_ts + 188;
  p_payload = ts_payload(p_ts);
  if (p_payload >= p_ts + 188)
    return p_ts + 188;
  return p_payload + *p_payload + 1;
}


x86 assembly (clang, -O0):
<ts_next_section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ts_get_unitstart@plt>
cmp    $0x0,%eax
jne    1151 <ts_next_section+0x31>
mov    -0x10(%rbp),%rax
add    $0x2f0,%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <ts_next_section+0x83>
mov    -0x10(%rbp),%rdi
call   1030 <ts_payload@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x2f0,%rcx
cmp    %rcx,%rax
jb     1189 <ts_next_section+0x69>
mov    -0x10(%rbp),%rax
add    $0x2f0,%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <ts_next_section+0x83>
mov    -0x18(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_next_section>:
push   %rbx
mov    %rdi,%rbx
call   1040 <ts_get_unitstart@plt>
test   %eax,%eax
je     114e <ts_next_section+0x2e>
mov    %rbx,%rdi
call   1030 <ts_payload@plt>
add    $0x2f0,%rbx
cmp    %rbx,%rax
jae    1155 <ts_next_section+0x35>
movslq (%rax),%rcx
lea    (%rax,%rcx,4),%rbx
add    $0x4,%rbx
jmp    1155 <ts_next_section+0x35>
add    $0x2f0,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i32* @ts_next_section(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = call i32 @ts_get_unitstart(i32* %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 188
store i32* %10, i32** %2
br label %28
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = call i32* @ts_payload(i32* %12)
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 188
%17 = icmp uge i32* %14, %16
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 188
store i32* %20, i32** %2
br label %28
21: ; preds = %11
%22 = load i32*, i32** %4
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %22, i64 %25
%27 = getelementptr inbounds i32, i32* %26, i64 1
store i32* %27, i32** %2
br label %28
28: ; preds = %21, %18, %8
%29 = load i32*, i32** %2
ret i32* %29
}

LLVM IR (-O2):
define i32* @ts_next_section(i32* %0) {
%2 = tail call i32 @ts_get_unitstart(i32* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = getelementptr inbounds i32, i32* %0, i64 188
br label %15
6: ; preds = %1
%7 = tail call i32* @ts_payload(i32* %0)
%8 = getelementptr inbounds i32, i32* %0, i64 188
%9 = icmp ult i32* %7, %8
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %7, i64 %12
%14 = getelementptr inbounds i32, i32* %13, i64 1
br label %15
15: ; preds = %6, %10, %4
%16 = phi i32* [ %14, %10 ], [ %5, %4 ], [ %8, %6 ]
ret i32* %16
}