#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ strncpy(char *, char *, int);
void main(void) {
  char *mystr = "This is a quick test";
  char c;
  char *cmdargs[16];
  char *buf;
  int j = 0, i = 0;
  c = *mystr;
  buf = (char *)malloc(32);
  while (c != '\0') {
    printf("The value of c is %c\n\n", c);
    if (c == ' ') {
      strncpy(cmdargs[i], buf, sizeof(buf));
      i++;
      j = 0;
      free(buf);
      buf = (char *)malloc(32);
      buf[0] = '\0';
    } else {
      buf[j] = c;
      j++;
    }
    mystr++;
    c = *mystr;
  }
  for (j = 0; j <= i; j++) {
    printf("cmdarg %d is %s\n", j, cmdargs[j]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x9c(%rbp)
movl   $0x0,-0xa0(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,-0x98(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
je     1252 <main+0x112>
movsbl -0x9(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x20,%eax
jne    1215 <main+0xd5>
movslq -0xa0(%rbp),%rax
mov    -0x90(%rbp,%rax,8),%rdi
ff
mov    -0x98(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strncpy@plt>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
movl   $0x0,-0x9c(%rbp)
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
movb   $0x0,(%rax)
jmp    1238 <main+0xf8>
mov    -0x9(%rbp),%dl
mov    -0x98(%rbp),%rax
movslq -0x9c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
jmp    1184 <main+0x44>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0xa0(%rbp),%eax
jg     12a5 <main+0x165>
mov    -0x9c(%rbp),%esi
movslq -0x9c(%rbp),%rax
mov    -0x90(%rbp,%rax,8),%rdx
ff
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    125c <main+0x11c>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x54,%r13b
mov    $0x1,%ebx
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    1191 <main+0x51>
xchg   %ax,%ax
movslq %r14d,%r14
mov    %r13b,(%r12,%r14,1)
add    $0x1,%r14d
lea    0xe7e(%rip),%rax
movzbl (%rbx,%rax,1),%r13d
add    $0x1,%rbx
cmp    $0x15,%rbx
je     11e0 <main+0xa0>
movsbl %r13b,%ebp
lea    0xe79(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x20,%bpl
jne    1170 <main+0x30>
movslq %r15d,%r15
mov    (%rsp,%r15,8),%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1040 <strncpy@plt>
add    $0x1,%r15d
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
movb   $0x0,(%rax)
xor    %r14d,%r14d
jmp    117b <main+0x3b>
test   %r15d,%r15d
js     1219 <main+0xd9>
add    $0x1,%r15d
lea    0xe3c(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1200 <main+0xc0>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"This is a quick test\00"
@.str.1 = [23 x i8] c"The value of c is %c\0A\0A\00"
@.str.2 = [17 x i8] c"cmdarg %d is %s\0A\00"
define void @main() {
%1 = alloca i8*
%2 = alloca i8
%3 = alloca [16 x i8*]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %1
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %1
%8 = load i8, i8* %7
store i8 %8, i8* %2
%9 = call i64 @malloc(i32 32)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
br label %11
11: ; preds = %45, %0
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %50
15: ; preds = %11
%16 = load i8, i8* %2
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 32
br i1 %21, label %22, label %37
22: ; preds = %15
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = load i8*, i8** %4
%28 = call i32 @strncpy(i8* %26, i8* %27, i32 8)
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
store i32 0, i32* %5
%31 = load i8*, i8** %4
%32 = call i32 @free(i8* %31)
%33 = call i64 @malloc(i32 32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %4
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 0
store i8 0, i8* %36
br label %45
37: ; preds = %15
%38 = load i8, i8* %2
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %45
45: ; preds = %37, %22
%46 = load i8*, i8** %1
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %1
%48 = load i8*, i8** %1
%49 = load i8, i8* %48
store i8 %49, i8* %2
br label %11
50: ; preds = %11
store i32 0, i32* %5
br label %51
51: ; preds = %62, %50
%52 = load i32, i32* %5
%53 = load i32, i32* %6
%54 = icmp sle i32 %52, %53
br i1 %54, label %55, label %65
55: ; preds = %51
%56 = load i32, i32* %5
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %56, i8* %60)
br label %62
62: ; preds = %55
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %51
65: ; preds = %51
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"This is a quick test\00"
@.str.1 = [23 x i8] c"The value of c is %c\0A\0A\00"
@.str.2 = [17 x i8] c"cmdarg %d is %s\0A\00"
define void @main() {
%1 = alloca [16 x i8*]
%2 = bitcast [16 x i8*]* %1 to i8*
%3 = tail call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i8*
br label %10
5: ; preds = %32
%6 = icmp slt i32 %35, 0
br i1 %6, label %47, label %7
7: ; preds = %5
%8 = add nuw i32 %35, 1
%9 = zext i32 %8 to i64
br label %39
10: ; preds = %0, %32
%11 = phi i32 [ 0, %0 ], [ %35, %32 ]
%12 = phi i32 [ 0, %0 ], [ %34, %32 ]
%13 = phi i8* [ %4, %0 ], [ %33, %32 ]
%14 = phi i8 [ 84, %0 ], [ %37, %32 ]
%15 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %0 ], [ %36, %32 ]
%16 = sext i8 %14 to i32
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp eq i8 %14, 32
br i1 %18, label %19, label %28
19: ; preds = %10
%20 = sext i32 %11 to i64
%21 = getelementptr inbounds [16 x i8*], [16 x i8*]* %1, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i32 @strncpy(i8* %22, i8* %13, i32 8)
%24 = add nsw i32 %11, 1
%25 = tail call i32 @free(i8* %13)
%26 = tail call i64 @malloc(i32 32)
%27 = inttoptr i64 %26 to i8*
store i8 0, i8* %27
br label %32
28: ; preds = %10
%29 = sext i32 %12 to i64
%30 = getelementptr inbounds i8, i8* %13, i64 %29
store i8 %14, i8* %30
%31 = add nsw i32 %12, 1
br label %32
32: ; preds = %28, %19
%33 = phi i8* [ %27, %19 ], [ %13, %28 ]
%34 = phi i32 [ 0, %19 ], [ %31, %28 ]
%35 = phi i32 [ %24, %19 ], [ %11, %28 ]
%36 = getelementptr inbounds i8, i8* %15, i64 1
%37 = load i8, i8* %36
%38 = icmp eq i8* %36, getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 20)
br i1 %38, label %5, label %10
39: ; preds = %7, %39
%40 = phi i64 [ 0, %7 ], [ %45, %39 ]
%41 = getelementptr inbounds [16 x i8*], [16 x i8*]* %1, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = trunc i64 %40 to i32
%44 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %43, i8* %42)
%45 = add nuw nsw i64 %40, 1
%46 = icmp eq i64 %45, %9
br i1 %46, label %47, label %39
47: ; preds = %39, %5
ret void
}