#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 */

/* Variables and functions */
scalar_t__ realloc(char **, int);
char *strdup(char const *);
void V3DAddLine(char ***line, int *total, const char *new_line) {
  int n;
  if ((line == NULL) || (total == NULL) || (new_line == NULL))
    return;
  if ((*total) < 0)
    (*total) = 0;
  n = (*total);
  (*total) = n + 1;
  (*line) = (char **)realloc(*line, (*total) * sizeof(char *));
  if ((*line) == NULL) {
    (*total) = 0;
    return;
  } else {
    (*line)[n] = (((new_line) != NULL) ? strdup(new_line) : NULL);
  }
  return;
}


x86 assembly (clang, -O0):
<V3DAddLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1155 <V3DAddLine+0x35>
cmpq   $0x0,-0x10(%rbp)
je     1155 <V3DAddLine+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    115a <V3DAddLine+0x3a>
jmp    1206 <V3DAddLine+0xe6>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1171 <V3DAddLine+0x51>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c6 <V3DAddLine+0xa6>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1206 <V3DAddLine+0xe6>
cmpq   $0x0,-0x18(%rbp)
je     11e3 <V3DAddLine+0xc3>
mov    -0x18(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    11ee <V3DAddLine+0xce>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11ee <V3DAddLine+0xce>
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1206 <V3DAddLine+0xe6>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<V3DAddLine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1187 <V3DAddLine+0x67>
mov    %rsi,%r15
test   %rsi,%rsi
je     1187 <V3DAddLine+0x67>
mov    %rdx,%r14
test   %rdx,%rdx
je     1187 <V3DAddLine+0x67>
mov    %rdi,%rbx
mov    (%r15),%eax
xor    %r13d,%r13d
test   %eax,%eax
cmovns %eax,%r13d
lea    0x1(%r13),%eax
mov    %eax,(%r15)
mov    (%rdi),%rdi
lea    0x8(,%r13,8),%esi
call   1030 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1180 <V3DAddLine+0x60>
mov    %rax,%r12
mov    %r14,%rdi
call   1040 <strdup@plt>
mov    %r13d,%ecx
mov    %rax,(%r12,%rcx,8)
jmp    1187 <V3DAddLine+0x67>
movl   $0x0,(%r15)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @V3DAddLine(i8*** %0, i32* %1, i8* %2) {
%4 = alloca i8***
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i8*** %0, i8**** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%8 = load i8***, i8**** %4
%9 = icmp eq i8*** %8, null
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13, %10, %3
br label %59
17: ; preds = %13
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i32*, i32** %5
store i32 0, i32* %22
br label %23
23: ; preds = %21, %17
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
%28 = load i32*, i32** %5
store i32 %27, i32* %28
%29 = load i8***, i8**** %4
%30 = load i8**, i8*** %29
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 8
%35 = trunc i64 %34 to i32
%36 = call i64 @realloc(i8** %30, i32 %35)
%37 = inttoptr i64 %36 to i8**
%38 = load i8***, i8**** %4
store i8** %37, i8*** %38
%39 = load i8***, i8**** %4
%40 = load i8**, i8*** %39
%41 = icmp eq i8** %40, null
br i1 %41, label %42, label %44
42: ; preds = %23
%43 = load i32*, i32** %5
store i32 0, i32* %43
br label %59
44: ; preds = %23
%45 = load i8*, i8** %6
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %6
%49 = call i8* @strdup(i8* %48)
br label %51
50: ; preds = %44
br label %51
51: ; preds = %50, %47
%52 = phi i8* [ %49, %47 ], [ null, %50 ]
%53 = load i8***, i8**** %4
%54 = load i8**, i8*** %53
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
store i8* %52, i8** %57
br label %58
58: ; preds = %51
br label %59
59: ; preds = %58, %42, %16
ret void
}

LLVM IR (-O2):
define void @V3DAddLine(i8*** %0, i32* %1, i8* %2) {
%4 = icmp eq i8*** %0, null
%5 = icmp eq i32* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i8* %2, null
%8 = or i1 %6, %7
br i1 %8, label %24, label %9
9: ; preds = %3
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
%12 = select i1 %11, i32 %10, i32 0
%13 = add nuw nsw i32 %12, 1
store i32 %13, i32* %1
%14 = load i8**, i8*** %0
%15 = shl i32 %13, 3
%16 = tail call i64 @realloc(i8** %14, i32 %15)
%17 = inttoptr i64 %16 to i8**
store i8** %17, i8*** %0
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %20
19: ; preds = %9
store i32 0, i32* %1
br label %24
20: ; preds = %9
%21 = tail call i8* @strdup(i8* %2)
%22 = zext i32 %12 to i64
%23 = getelementptr inbounds i8*, i8** %17, i64 %22
store i8* %21, i8** %23
br label %24
24: ; preds = %3, %20, %19
ret void
}