#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 makeargv(char const *, char ***);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  const char *str = "hello world this is nvidia";
  char **argv;
  int numtokens = makeargv(str, &argv);
  int i = 0;
  for (i = 0; i < numtokens; i++)
    printf("%s\n", argv[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <makeargv@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    118a <main+0x6a>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1158 <main+0x38>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <makeargv@plt>
test   %eax,%eax
jle    116a <main+0x4a>
mov    %eax,%r15d
xor    %ebx,%ebx
lea    0xed1(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <main+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"hello world this is nvidia\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @makeargv(i8* %6, i8*** %3)
store i32 %7, i32* %4
store i32 0, i32* %5
store i32 0, i32* %5
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i8**, i8*** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %12
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %8
22: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"hello world this is nvidia\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i8**
%2 = bitcast i8*** %1 to i8*
%3 = call i32 @makeargv(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8*** %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %0
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %13, %7 ]
%9 = load i8**, i8*** %1
%10 = getelementptr inbounds i8*, i8** %9, i64 %8
%11 = load i8*, i8** %10
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %15, label %7
15: ; preds = %7, %0
ret i32 0
}