#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 /*<<< orphan*/ free(char *);
int l2a(char *, char **);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int line2argv(int *pargc, char ***pargv, char *line) {
  char *lincp;
  if (line == NULL) {
    *pargc = 0;
    **pargv = NULL;
    return (0);
  }
  lincp = (char *)malloc((strlen(line) + 2) * sizeof(char));
  strcpy(lincp, line);
  lincp[strlen(line) + 1] = '\0';
  *pargc = l2a(lincp, NULL);
  *pargv = (char **)malloc(((*pargc) + 1) * sizeof(char *));
  l2a(lincp, *pargv);
  free(lincp);
  return (*pargc);
}


x86 assembly (clang, -O0):
<line2argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1193 <line2argv+0x43>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1235 <line2argv+0xe5>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <l2a@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1060 <l2a@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line2argv>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdx,%rdx
je     11c8 <line2argv+0x78>
mov    %rdx,%rbx
mov    %rdx,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%r12,1)
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <l2a@plt>
mov    %eax,(%r15)
lea    0x8(,%rax,8),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
mov    %rax,%rsi
call   1060 <l2a@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    (%r15),%eax
jmp    11db <line2argv+0x8b>
movl   $0x0,(%r15)
mov    (%r14),%rax
movq   $0x0,(%rax)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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