#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 /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint16_t;

/* Variables and functions */
scalar_t__ bin_to_uint16(int /*<<< orphan*/ *);
int bin_to_uint32(int /*<<< orphan*/ *);
char *find_irep_symbol(uint8_t *p, int n) {
  int cnt = bin_to_uint32(p);
  if (n >= cnt)
    return 0;
  p += 4;
  while (n > 0) {
    uint16_t s = bin_to_uint16(p);
    p += 2 + s + 1;
    n--;
  }
  return (char *)p + 2;
}


x86 assembly (clang, -O0):
<find_irep_symbol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <bin_to_uint32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1154 <find_irep_symbol+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <find_irep_symbol+0x89>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    119d <find_irep_symbol+0x7d>
mov    -0x10(%rbp),%rdi
call   1040 <bin_to_uint16@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
add    $0x1,%rax
shl    $0x2,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <find_irep_symbol+0x40>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_irep_symbol>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <bin_to_uint32@plt>
cmp    %ebp,%eax
jle    115e <find_irep_symbol+0x3e>
add    $0x10,%rbx
test   %ebp,%ebp
jle    1158 <find_irep_symbol+0x38>
add    $0x1,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <bin_to_uint16@plt>
lea    (%rbx,%rax,4),%rbx
add    $0xc,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1140 <find_irep_symbol+0x20>
add    $0x2,%rbx
jmp    1160 <find_irep_symbol+0x40>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @find_irep_symbol(i32* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32*, i32** %4
%9 = call i32 @bin_to_uint32(i32* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %34
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i64 4
store i32* %16, i32** %4
br label %17
17: ; preds = %20, %14
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i32*, i32** %4
%22 = call i64 @bin_to_uint16(i32* %21)
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = add nsw i64 2, %23
%25 = add nsw i64 %24, 1
%26 = load i32*, i32** %4
%27 = getelementptr inbounds i32, i32* %26, i64 %25
store i32* %27, i32** %4
%28 = load i32, i32* %5
%29 = add nsw i32 %28, -1
store i32 %29, i32* %5
br label %17
30: ; preds = %17
%31 = load i32*, i32** %4
%32 = bitcast i32* %31 to i8*
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8* %33, i8** %3
br label %34
34: ; preds = %30, %13
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
define i8* @find_irep_symbol(i32* %0, i32 %1) {
%3 = tail call i32 @bin_to_uint32(i32* %0)
%4 = icmp sgt i32 %3, %1
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = getelementptr inbounds i32, i32* %0, i64 4
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %16
8: ; preds = %5, %8
%9 = phi i32* [ %13, %8 ], [ %6, %5 ]
%10 = phi i32 [ %14, %8 ], [ %1, %5 ]
%11 = tail call i64 @bin_to_uint16(i32* %9)
%12 = add nsw i64 %11, 3
%13 = getelementptr inbounds i32, i32* %9, i64 %12
%14 = add nsw i32 %10, -1
%15 = icmp ugt i32 %10, 1
br i1 %15, label %8, label %16
16: ; preds = %8, %5
%17 = phi i32* [ %6, %5 ], [ %13, %8 ]
%18 = bitcast i32* %17 to i8*
%19 = getelementptr inbounds i8, i8* %18, i64 2
br label %20
20: ; preds = %2, %16
%21 = phi i8* [ %19, %16 ], [ null, %2 ]
ret i8* %21
}