#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 */
struct castle_norm_key {
  int dummy;
};

/* Variables and functions */
struct castle_norm_key *castle_norm_key_copy(struct castle_norm_key const *,
                                             struct castle_norm_key *,
                                             size_t *);
size_t castle_norm_key_dim_get(unsigned char const **);
struct castle_norm_key *castle_norm_key_dim_inc(struct castle_norm_key *,
                                                size_t);
int /*<<< orphan*/ castle_norm_key_len_get(struct castle_norm_key *,
                                           unsigned char const **);
struct castle_norm_key *castle_norm_key_next(const struct castle_norm_key *src,
                                             struct castle_norm_key *dst,
                                             size_t *dst_len) {
  const unsigned char *data;
  size_t n_dim;
  if (!(dst = castle_norm_key_copy(src, dst, dst_len)))
    return NULL;
  castle_norm_key_len_get(dst, &data);
  n_dim = castle_norm_key_dim_get(&data);
  return castle_norm_key_dim_inc(dst, n_dim - 1);
}


x86 assembly (clang, -O0):
<castle_norm_key_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <castle_norm_key_copy@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1180 <castle_norm_key_next+0x40>
movq   $0x0,-0x8(%rbp)
jmp    11af <castle_norm_key_next+0x6f>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <castle_norm_key_len_get@plt>
lea    -0x28(%rbp),%rdi
call   1060 <castle_norm_key_dim_get@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
sub    $0x1,%rsi
call   1040 <castle_norm_key_dim_inc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<castle_norm_key_next>:
push   %r14
push   %rbx
push   %rax
call   1050 <castle_norm_key_copy@plt>
test   %rax,%rax
je     1175 <castle_norm_key_next+0x35>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <castle_norm_key_len_get@plt>
mov    %r14,%rdi
call   1060 <castle_norm_key_dim_get@plt>
lea    -0x1(%rax),%rsi
mov    %rbx,%rdi
call   1040 <castle_norm_key_dim_inc@plt>
jmp    1177 <castle_norm_key_next+0x37>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.castle_norm_key = type { i32 }
define %struct.castle_norm_key* @castle_norm_key_next(%struct.castle_norm_key* %0, %struct.castle_norm_key* %1, i64* %2) {
%4 = alloca %struct.castle_norm_key*
%5 = alloca %struct.castle_norm_key*
%6 = alloca %struct.castle_norm_key*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
store %struct.castle_norm_key* %0, %struct.castle_norm_key** %5
store %struct.castle_norm_key* %1, %struct.castle_norm_key** %6
store i64* %2, i64** %7
%10 = load %struct.castle_norm_key*, %struct.castle_norm_key** %5
%11 = load %struct.castle_norm_key*, %struct.castle_norm_key** %6
%12 = load i64*, i64** %7
%13 = call %struct.castle_norm_key* @castle_norm_key_copy(%struct.castle_norm_key* %10, %struct.castle_norm_key* %11, i64* %12)
store %struct.castle_norm_key* %13, %struct.castle_norm_key** %6
%14 = icmp ne %struct.castle_norm_key* %13, null
br i1 %14, label %16, label %15
15: ; preds = %3
store %struct.castle_norm_key* null, %struct.castle_norm_key** %4
br label %24
16: ; preds = %3
%17 = load %struct.castle_norm_key*, %struct.castle_norm_key** %6
%18 = call i32 @castle_norm_key_len_get(%struct.castle_norm_key* %17, i8** %8)
%19 = call i64 @castle_norm_key_dim_get(i8** %8)
store i64 %19, i64* %9
%20 = load %struct.castle_norm_key*, %struct.castle_norm_key** %6
%21 = load i64, i64* %9
%22 = sub i64 %21, 1
%23 = call %struct.castle_norm_key* @castle_norm_key_dim_inc(%struct.castle_norm_key* %20, i64 %22)
store %struct.castle_norm_key* %23, %struct.castle_norm_key** %4
br label %24
24: ; preds = %16, %15
%25 = load %struct.castle_norm_key*, %struct.castle_norm_key** %4
ret %struct.castle_norm_key* %25
}

LLVM IR (-O2):
%struct.castle_norm_key = type { i32 }
define %struct.castle_norm_key* @castle_norm_key_next(%struct.castle_norm_key* %0, %struct.castle_norm_key* %1, i64* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call %struct.castle_norm_key* @castle_norm_key_copy(%struct.castle_norm_key* %0, %struct.castle_norm_key* %1, i64* %2)
%7 = icmp eq %struct.castle_norm_key* %6, null
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = call i32 @castle_norm_key_len_get(%struct.castle_norm_key* %6, i8** %4)
%10 = call i64 @castle_norm_key_dim_get(i8** %4)
%11 = add i64 %10, -1
%12 = call %struct.castle_norm_key* @castle_norm_key_dim_inc(%struct.castle_norm_key* %6, i64 %11)
br label %13
13: ; preds = %3, %8
%14 = phi %struct.castle_norm_key* [ %12, %8 ], [ null, %3 ]
ret %struct.castle_norm_key* %14
}