#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 *_nextargv(char **, char *);
int _sizeargv(char *, char *);
int /*<<< orphan*/ argv_destroy(char **);
scalar_t__ malloc(int);
char **argv_create(char *cmdline, char *ignore) {
  int argc = _sizeargv(cmdline, ignore);
  char **argv = (char **)malloc(sizeof(char *) * (argc + 1));
  int i;
  if (!argv)
    return (NULL);
  for (i = 0; i < argc; i++) {
    if (!(argv[i] = _nextargv(&cmdline, ignore))) {
      argv_destroy(argv);
      return (NULL);
    }
  }
  argv[i] = NULL;
  return argv;
}


x86 assembly (clang, -O0):
<argv_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <_sizeargv@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%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    118f <argv_create+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    1206 <argv_create+0xc6>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ee <argv_create+0xae>
mov    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1060 <_nextargv@plt>
mov    -0x28(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11db <argv_create+0x9b>
mov    -0x28(%rbp),%rdi
call   1040 <argv_destroy@plt>
movq   $0x0,-0x8(%rbp)
jmp    1206 <argv_create+0xc6>
jmp    11e0 <argv_create+0xa0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1196 <argv_create+0x56>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argv_create>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,0x8(%rsp)
call   1030 <_sizeargv@plt>
mov    %eax,%r15d
lea    0x8(,%r15,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c6 <argv_create+0x86>
mov    %rax,%r13
test   %r15d,%r15d
jle    11b0 <argv_create+0x70>
mov    %r15d,%r12d
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <_nextargv@plt>
mov    %rax,0x0(%r13,%rbx,8)
test   %rax,%rax
je     11be <argv_create+0x7e>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <argv_create+0x50>
jmp    11b3 <argv_create+0x73>
xor    %r12d,%r12d
movq   $0x0,0x0(%r13,%r12,8)
jmp    11c9 <argv_create+0x89>
mov    %r13,%rdi
call   1040 <argv_destroy@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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