#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 scalar_t__ uint32_t;
struct iscsi_node {
  int dummy;
};
struct iscsi_context {
  int dummy;
};

/* Variables and functions */
int _grow_node_array(struct iscsi_context *, struct iscsi_node ***,
                     scalar_t__ *);
int nodes_append(struct iscsi_context *ctx, struct iscsi_node ***nodes,
                 uint32_t *real_node_count, uint32_t *array_size,
                 struct iscsi_node *node) {
  int rc = 0;
  if (*real_node_count >= *array_size)
    do {
      rc = _grow_node_array(ctx, nodes, array_size);
      if (rc != 0)
        goto out;
    } while (0);
  (*nodes)[(*real_node_count)++] = node;
out:
  return rc;
}


x86 assembly (clang, -O0):
<nodes_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jl     1179 <nodes_append+0x69>
jmp    114c <nodes_append+0x3c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <_grow_node_array@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     116f <nodes_append+0x5f>
jmp    1199 <nodes_append+0x89>
jmp    1174 <nodes_append+0x64>
jmp    1179 <nodes_append+0x69>
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rsi
mov    (%rsi),%rcx
mov    %rcx,%rdi
add    $0x1,%rdi
mov    %rdi,(%rsi)
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nodes_append>:
push   %r15
push   %r14
push   %rbx
mov    %r8,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    (%rdx),%rax
cmp    (%rcx),%rax
jl     1138 <nodes_append+0x28>
mov    %r15,%rsi
mov    %rcx,%rdx
call   1030 <_grow_node_array@plt>
test   %eax,%eax
jne    1148 <nodes_append+0x38>
mov    (%rbx),%rax
mov    (%r15),%rcx
lea    0x1(%rax),%rdx
mov    %rdx,(%rbx)
mov    %r14,(%rcx,%rax,8)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.iscsi_context = type { i32 }
%struct.iscsi_node = type { i32 }
define i32 @nodes_append(%struct.iscsi_context* %0, %struct.iscsi_node*** %1, i64* %2, i64* %3, %struct.iscsi_node* %4) {
%6 = alloca %struct.iscsi_context*
%7 = alloca %struct.iscsi_node***
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca %struct.iscsi_node*
%11 = alloca i32
store %struct.iscsi_context* %0, %struct.iscsi_context** %6
store %struct.iscsi_node*** %1, %struct.iscsi_node**** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
store %struct.iscsi_node* %4, %struct.iscsi_node** %10
store i32 0, i32* %11
%12 = load i64*, i64** %8
%13 = load i64, i64* %12
%14 = load i64*, i64** %9
%15 = load i64, i64* %14
%16 = icmp sge i64 %13, %15
br i1 %16, label %17, label %28
17: ; preds = %5
br label %18
18: ; preds = %17
%19 = load %struct.iscsi_context*, %struct.iscsi_context** %6
%20 = load %struct.iscsi_node***, %struct.iscsi_node**** %7
%21 = load i64*, i64** %9
%22 = call i32 @_grow_node_array(%struct.iscsi_context* %19, %struct.iscsi_node*** %20, i64* %21)
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
br label %36
26: ; preds = %18
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27, %5
%29 = load %struct.iscsi_node*, %struct.iscsi_node** %10
%30 = load %struct.iscsi_node***, %struct.iscsi_node**** %7
%31 = load %struct.iscsi_node**, %struct.iscsi_node*** %30
%32 = load i64*, i64** %8
%33 = load i64, i64* %32
%34 = add nsw i64 %33, 1
store i64 %34, i64* %32
%35 = getelementptr inbounds %struct.iscsi_node*, %struct.iscsi_node** %31, i64 %33
store %struct.iscsi_node* %29, %struct.iscsi_node** %35
br label %36
36: ; preds = %28, %25
%37 = load i32, i32* %11
ret i32 %37
}

LLVM IR (-O2):
%struct.iscsi_context = type { i32 }
%struct.iscsi_node = type { i32 }
define i32 @nodes_append(%struct.iscsi_context* %0, %struct.iscsi_node*** %1, i64* nocapture %2, i64* %3, %struct.iscsi_node* %4) {
%6 = load i64, i64* %2
%7 = load i64, i64* %3
%8 = icmp slt i64 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = tail call i32 @_grow_node_array(%struct.iscsi_context* %0, %struct.iscsi_node*** %1, i64* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i64, i64* %2
br label %14
14: ; preds = %12, %5
%15 = phi i64 [ %13, %12 ], [ %6, %5 ]
%16 = load %struct.iscsi_node**, %struct.iscsi_node*** %1
%17 = add nsw i64 %15, 1
store i64 %17, i64* %2
%18 = getelementptr inbounds %struct.iscsi_node*, %struct.iscsi_node** %16, i64 %15
store %struct.iscsi_node* %4, %struct.iscsi_node** %18
br label %19
19: ; preds = %9, %14
%20 = phi i32 [ %10, %9 ], [ 0, %14 ]
ret i32 %20
}