#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 *chl_next_arg(char *);
char **std_malloc(char);
char **std_realloc(char **, char);
char chl_get_args(char *(**dst), char *args) {
  char argsn = 0;
  char *arg;
  if (!(arg = chl_next_arg(args)))
    return 0;
  *dst = std_malloc(++argsn * sizeof(char *));
  **dst = arg;
  while ((arg = chl_next_arg(NULL))) {
    *dst = std_realloc(*dst, ++argsn * sizeof(char *));
    *(*dst + (argsn - 1)) = arg;
  }
  return argsn;
}


x86 assembly (clang, -O0):
<chl_get_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <chl_next_arg@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1164 <chl_get_args+0x34>
movb   $0x0,-0x1(%rbp)
jmp    11f8 <chl_get_args+0xc8>
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
movsbq %al,%rax
shl    $0x3,%rax
movsbl %al,%edi
call   1050 <std_malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <chl_next_arg@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f2 <chl_get_args+0xc2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
movsbq %al,%rax
shl    $0x3,%rax
movsbl %al,%esi
call   1030 <std_realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl -0x19(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1194 <chl_get_args+0x64>
mov    -0x19(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chl_get_args>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <chl_next_arg@plt>
test   %rax,%rax
je     11a1 <chl_get_args+0x71>
mov    %rax,%rbx
mov    $0x8,%edi
call   1050 <std_malloc@plt>
mov    %rax,(%r14)
mov    %rbx,(%rax)
xor    %edi,%edi
call   1040 <chl_next_arg@plt>
test   %rax,%rax
je     11a5 <chl_get_args+0x75>
mov    %rax,%r15
mov    $0x1,%bpl
mov    $0x10,%bl
xchg   %ax,%ax
mov    (%r14),%rdi
add    $0x1,%bpl
movsbl %bl,%ebx
mov    %ebx,%esi
call   1030 <std_realloc@plt>
mov    %rax,(%r14)
movsbq %bpl,%rcx
mov    %r15,-0x8(%rax,%rcx,8)
xor    %edi,%edi
call   1040 <chl_next_arg@plt>
mov    %rax,%r15
add    $0x8,%bl
test   %rax,%rax
jne    1170 <chl_get_args+0x40>
jmp    11a8 <chl_get_args+0x78>
xor    %ebp,%ebp
jmp    11a8 <chl_get_args+0x78>
mov    $0x1,%bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @chl_get_args(i8*** %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8***
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
store i8*** %0, i8**** %4
store i8* %1, i8** %5
store i8 0, i8* %6
%8 = load i8*, i8** %5
%9 = call i8* @chl_next_arg(i8* %8)
store i8* %9, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i8 0, i8* %3
br label %46
12: ; preds = %2
%13 = load i8, i8* %6
%14 = add i8 %13, 1
store i8 %14, i8* %6
%15 = sext i8 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i8
%18 = call i8** @std_malloc(i8 signext %17)
%19 = load i8***, i8**** %4
store i8** %18, i8*** %19
%20 = load i8*, i8** %7
%21 = load i8***, i8**** %4
%22 = load i8**, i8*** %21
store i8* %20, i8** %22
br label %23
23: ; preds = %26, %12
%24 = call i8* @chl_next_arg(i8* null)
store i8* %24, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %44
26: ; preds = %23
%27 = load i8***, i8**** %4
%28 = load i8**, i8*** %27
%29 = load i8, i8* %6
%30 = add i8 %29, 1
store i8 %30, i8* %6
%31 = sext i8 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i8
%34 = call i8** @std_realloc(i8** %28, i8 signext %33)
%35 = load i8***, i8**** %4
store i8** %34, i8*** %35
%36 = load i8*, i8** %7
%37 = load i8***, i8**** %4
%38 = load i8**, i8*** %37
%39 = load i8, i8* %6
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %38, i64 %42
store i8* %36, i8** %43
br label %23
44: ; preds = %23
%45 = load i8, i8* %6
store i8 %45, i8* %3
br label %46
46: ; preds = %44, %11
%47 = load i8, i8* %3
ret i8 %47
}

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