#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 */
int count_params(char const *, int);
char *get_param(char const **, int *);
char **malloc(int);
int strlen(char const *);
void paramline_to_argcv(const char *cmdp, int *argcp, char ***argvp) {
  int len;
  int argc;
  char **argv;
  len = strlen(cmdp);
  argc = count_params(cmdp, len);
  argv = malloc((argc + 1) * sizeof *argv);
  if (!argv)
    argc = -1;
  else {
    int i;
    for (i = 0; i < argc; ++i)
      argv[i] = get_param(&cmdp, &len);
    argv[i] = 0;
    *argcp = argc;
    *argvp = argv;
  }
}


x86 assembly (clang, -O0):
<paramline_to_argcv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <count_params@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <paramline_to_argcv+0x5d>
movl   $0xffffffff,-0x20(%rbp)
jmp    11fe <paramline_to_argcv+0xbe>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11da <paramline_to_argcv+0x9a>
lea    -0x8(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <get_param@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a4 <paramline_to_argcv+0x64>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paramline_to_argcv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rdi,0x20(%rsp)
call   1030 <strlen@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <count_params@plt>
mov    %eax,%r12d
lea    0x8(,%r12,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11e6 <paramline_to_argcv+0xa6>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11d4 <paramline_to_argcv+0x94>
mov    %rbp,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    %r12d,%r14d
xor    %r15d,%r15d
lea    0x20(%rsp),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <get_param@plt>
mov    %rax,(%rbx,%r15,8)
add    $0x1,%r15
cmp    %r15,%r14
jne    11b0 <paramline_to_argcv+0x70>
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%rbp
jmp    11d7 <paramline_to_argcv+0x97>
xor    %r14d,%r14d
movq   $0x0,(%rbx,%r14,8)
mov    %r12d,0x0(%rbp)
mov    %rbx,(%r15)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @paramline_to_argcv(i8* %0, i32* nocapture writeonly %1, i8*** nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 @strlen(i8* %0)
store i32 %7, i32* %5
%8 = tail call i32 @count_params(i8* %0, i32 %7)
%9 = shl i32 %8, 3
%10 = add i32 %9, 8
%11 = tail call i8** @malloc(i32 %10)
%12 = icmp eq i8** %11, null
br i1 %12, label %28, label %13
13: ; preds = %3
%14 = icmp sgt i32 %8, 0
br i1 %14, label %15, label %25
15: ; preds = %13
%16 = zext i32 %8 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %21, %17 ]
%19 = call i8* @get_param(i8** %4, i32* %5)
%20 = getelementptr inbounds i8*, i8** %11, i64 %18
store i8* %19, i8** %20
%21 = add nuw nsw i64 %18, 1
%22 = icmp eq i64 %21, %16
br i1 %22, label %23, label %17
23: ; preds = %17
%24 = zext i32 %8 to i64
br label %25
25: ; preds = %13, %23
%26 = phi i64 [ %24, %23 ], [ 0, %13 ]
%27 = getelementptr inbounds i8*, i8** %11, i64 %26
store i8* null, i8** %27
store i32 %8, i32* %1
store i8** %11, i8*** %2
br label %28
28: ; preds = %3, %25
ret void
}