#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 */
char **realloc(char **, size_t);
char *strdup(char *);
scalar_t__ strlen(char *);
char **loadarg(char *pack) {
  size_t i;
  char *top;
  char **argv;
  argv = NULL;
  top = pack;
  for (i = 0;; i++) {
    argv = realloc(argv, (i + 1) * sizeof(char *));
    if (top[0] == '\b') {
      argv[i] = NULL;
      break;
    } else {
      argv[i] = strdup(top);
    }
    top += strlen(top) + 1;
  }
  return argv;
}


x86 assembly (clang, -O0):
<loadarg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
shl    $0x3,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x8,%eax
jne    1192 <loadarg+0x62>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    11d0 <loadarg+0xa0>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1154 <loadarg+0x24>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadarg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
cmpb   $0x8,(%r15)
jne    1166 <loadarg+0x26>
xor    %r13d,%r13d
jmp    11b0 <loadarg+0x70>
mov    $0x10,%ebx
xor    %r13d,%r13d
xchg   %ax,%ax
mov    %r15,%rdi
call   1060 <strdup@plt>
mov    %rax,(%r14,%r13,8)
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
lea    (%rax,%r15,1),%rbp
add    $0x1,%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,%r14
add    $0x1,%r13
add    $0x8,%rbx
cmpb   $0x8,0x1(%r12,%r15,1)
mov    %rbp,%r15
jne    1170 <loadarg+0x30>
movq   $0x0,(%r14,%r13,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8** @loadarg(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(8) i8* @malloc(i64 8)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 8
br i1 %4, label %5, label %9
5: ; preds = %9, %1
%6 = phi i64 [ 0, %1 ], [ %11, %9 ]
%7 = phi i8** [ %2, %1 ], [ %21, %9 ]
%8 = getelementptr inbounds i8*, i8** %7, i64 %6
store i8* null, i8** %8
ret i8** %7
9: ; preds = %1, %9
%10 = phi i8** [ %21, %9 ], [ %2, %1 ]
%11 = phi i64 [ %19, %9 ], [ 1, %1 ]
%12 = phi i8* [ %18, %9 ], [ %0, %1 ]
%13 = phi i64 [ %11, %9 ], [ 0, %1 ]
%14 = tail call i8* @strdup(i8* %12)
%15 = getelementptr inbounds i8*, i8** %10, i64 %13
store i8* %14, i8** %15
%16 = tail call i64 @strlen(i8* %12)
%17 = add nsw i64 %16, 1
%18 = getelementptr inbounds i8, i8* %12, i64 %17
%19 = add i64 %11, 1
%20 = shl i64 %19, 3
%21 = tail call i8** @realloc(i8** %10, i64 %20)
%22 = load i8, i8* %18
%23 = icmp eq i8 %22, 8
br i1 %23, label %5, label %9
}