#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;

/* Variables and functions */
int knot_wire_get_pointer(int /*<<< orphan*/ const *);
scalar_t__ knot_wire_is_pointer(int /*<<< orphan*/ const *);
const uint8_t *knot_wire_seek_label(const uint8_t *lp, const uint8_t *wire) {
  while (knot_wire_is_pointer(lp)) {
    if (!wire)
      return NULL;
    lp = wire + knot_wire_get_pointer(lp);
  }
  return lp;
}


x86 assembly (clang, -O0):
<knot_wire_seek_label>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <knot_wire_is_pointer@plt>
cmp    $0x0,%rax
je     1185 <knot_wire_seek_label+0x65>
cmpq   $0x0,-0x18(%rbp)
jne    115b <knot_wire_seek_label+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    118d <knot_wire_seek_label+0x6d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <knot_wire_get_pointer@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <knot_wire_seek_label+0x10>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<knot_wire_seek_label>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <knot_wire_is_pointer@plt>
test   %rax,%rax
je     115f <knot_wire_seek_label+0x3f>
test   %r14,%r14
je     115d <knot_wire_seek_label+0x3d>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <knot_wire_get_pointer@plt>
cltq
lea    (%r14,%rax,4),%rbx
mov    %rbx,%rdi
call   1030 <knot_wire_is_pointer@plt>
test   %rax,%rax
jne    1140 <knot_wire_seek_label+0x20>
jmp    115f <knot_wire_seek_label+0x3f>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @knot_wire_seek_label(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %6
6: ; preds = %14, %2
%7 = load i32*, i32** %4
%8 = call i64 @knot_wire_is_pointer(i32* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i32* null, i32** %3
br label %22
14: ; preds = %10
%15 = load i32*, i32** %5
%16 = load i32*, i32** %4
%17 = call i32 @knot_wire_get_pointer(i32* %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %15, i64 %18
store i32* %19, i32** %4
br label %6
20: ; preds = %6
%21 = load i32*, i32** %4
store i32* %21, i32** %3
br label %22
22: ; preds = %20, %13
%23 = load i32*, i32** %3
ret i32* %23
}

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