#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 */
scalar_t__ malloc(int);
int std_arg_parser(char *str, char **argv_p[]) {
  int argc = 1;
  char **argv = (char **)malloc(6 * sizeof(char *));
  *argv_p = argv;
  *argv++;
  *argv++ = str;
  while (*str != '\0') {
    if (*str == ' ') {
      *str++ = '\0';
      *argv++ = str;
      argc++;
      while (*str == ' ')
        str++;
    }
    str++;
  }
  return argc;
}


x86 assembly (clang, -O0):
<std_arg_parser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    $0x30,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ea <std_arg_parser+0xda>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11d9 <std_arg_parser+0xc9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11d4 <std_arg_parser+0xc4>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <std_arg_parser+0xa3>
jmp    11d9 <std_arg_parser+0xc9>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1162 <std_arg_parser+0x52>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<std_arg_parser>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x30,%edi
call   1030 <malloc@plt>
mov    %rax,(%r14)
mov    %rbx,0x8(%rax)
add    $0x10,%rax
mov    $0x1,%ecx
jmp    1148 <std_arg_parser+0x38>
cs nopw 0x0(%rax,%rax,1)
test   %dl,%dl
je     1173 <std_arg_parser+0x63>
add    $0x1,%rbx
mov    (%rbx),%dl
cmp    $0x20,%dl
jne    1140 <std_arg_parser+0x30>
lea    0x1(%rbx),%rdx
movb   $0x0,(%rbx)
mov    %rdx,(%rax)
nopl   0x0(%rax)
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1160 <std_arg_parser+0x50>
add    $0x8,%rax
add    $0x1,%ecx
jmp    1144 <std_arg_parser+0x34>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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