#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*/ str;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int makearg(char *, char ***);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char str[255 + 1];
  int i;
  int argc;
  char **argv;
  printf("Input string to Parse (max input %i chars, max token %i chars):\n>",
         255, 32);
  fgets(str, (int)sizeof(str), stdin);
  if (strlen(str) > 255) {
    printf("Error: Max input size exceeded\n");
    return 0;
  }
  argc = makearg(str, &argv);
  if (argc > 0) {
    printf("makearg() Returned Successfully!\n");
    printf("Num of Args:%i\n", argc);
    for (i = 0; i < argc; i++) {
      printf("Arg #%i:%s\n", i + 1, argv[i]);
    }
  } else if (argc == 0)
    printf("Error: Input string empty\n");
  else if (argc == -1)
    printf("Error: Max token size exceeded\n");
  else
    printf("Error: Unrecognized error. What have you done?\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0xff,%esi
mov    $0x20,%edx
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xff,%eax
jle    11b5 <main+0x75>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ba <main+0x17a>
lea    -0x110(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <makearg@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x118(%rbp)
jle    125b <main+0x11b>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x118(%rbp),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x114(%rbp)
mov    -0x114(%rbp),%eax
cmp    -0x118(%rbp),%eax
jge    1256 <main+0x116>
mov    -0x114(%rbp),%esi
add    $0x1,%esi
mov    -0x120(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    1207 <main+0xc7>
jmp    12b3 <main+0x173>
cmpl   $0x0,-0x118(%rbp)
jne    127b <main+0x13b>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ae <main+0x16e>
cmpl   $0xffffffff,-0x118(%rbp)
jne    129b <main+0x15b>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a9 <main+0x169>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ae <main+0x16e>
jmp    12b3 <main+0x173>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
lea    0xe9d(%rip),%rdi
mov    $0xff,%esi
mov    $0x20,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0xff,%eax
jle    11aa <main+0x5a>
lea    0xf42(%rip),%rdi
jmp    1232 <main+0xe2>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <makearg@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1210 <main+0xc0>
lea    0xf00(%rip),%rdi
call   1030 <puts@plt>
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%r15d
lea    0xe6d(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rdx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %rbx,%r15
jne    11f0 <main+0xa0>
jmp    1237 <main+0xe7>
cmp    $0xffffffff,%ebx
lea    0xe73(%rip),%rax
lea    0xe3d(%rip),%rcx
cmove  %rax,%rcx
test   %ebx,%ebx
lea    0xe7e(%rip),%rdi
cmovne %rcx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [66 x i8] c"Input string to Parse (max input %i chars, max token %i chars):\0A>\00"
@stdin = global i32 0
@.str.1 = [32 x i8] c"Error: Max input size exceeded\0A\00"
@.str.2 = [34 x i8] c"makearg() Returned Successfully!\0A\00"
@.str.3 = [16 x i8] c"Num of Args:%i\0A\00"
@.str.4 = [12 x i8] c"Arg #%i:%s\0A\00"
@.str.5 = [27 x i8] c"Error: Input string empty\0A\00"
@.str.6 = [32 x i8] c"Error: Max token size exceeded\0A\00"
@.str.7 = [48 x i8] c"Error: Unrecognized error. What have you done?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 255, i32 32)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 256, i32 %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = icmp sgt i32 %11, 255
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %56
15: ; preds = %0
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = call i32 @makearg(i8* %16, i8*** %5)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %41
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %22)
store i32 0, i32* %3
br label %24
24: ; preds = %37, %20
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
%31 = load i8**, i8*** %5
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %30, i8* %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %24
40: ; preds = %24
br label %55
41: ; preds = %15
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %54
46: ; preds = %41
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %53
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
br label %54
54: ; preds = %53, %44
br label %55
55: ; preds = %54, %40
store i32 0, i32* %1
br label %56
56: ; preds = %55, %13
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [66 x i8] c"Input string to Parse (max input %i chars, max token %i chars):\0A>\00"
@stdin = global i32 0
@.str.3 = [16 x i8] c"Num of Args:%i\0A\00"
@.str.4 = [12 x i8] c"Arg #%i:%s\0A\00"
@str = [47 x i8] c"Error: Unrecognized error. What have you done?\00"
@str.8 = [31 x i8] c"Error: Max token size exceeded\00"
@str.9 = [26 x i8] c"Error: Input string empty\00"
@str.10 = [33 x i8] c"makearg() Returned Successfully!\00"
@str.11 = [31 x i8] c"Error: Max input size exceeded\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i8**
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i8*** %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 255, i32 32)
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 256, i32 %6)
%8 = call i32 @strlen(i8* %3)
%9 = icmp sgt i32 %8, 255
br i1 %9, label %31, label %10
10: ; preds = %0
%11 = call i32 @makearg(i8* %3, i8*** %2)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.10, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%16 = zext i32 %11 to i64
br label %17
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %19, %17 ]
%19 = add nuw nsw i64 %18, 1
%20 = load i8**, i8*** %2
%21 = getelementptr inbounds i8*, i8** %20, i64 %18
%22 = load i8*, i8** %21
%23 = trunc i64 %19 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %23, i8* %22)
%25 = icmp eq i64 %19, %16
br i1 %25, label %34, label %17
26: ; preds = %10
%27 = icmp eq i32 %11, -1
%28 = select i1 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0)
%29 = icmp eq i32 %11, 0
%30 = select i1 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0), i8* %28
br label %31
31: ; preds = %26, %0
%32 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @str.11, i64 0, i64 0), %0 ], [ %30, %26 ]
%33 = call i32 @puts(i8* dereferenceable(1) %32)
br label %34
34: ; preds = %17, %31
ret i32 0
}