#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 *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char **strasp(char *, char const *);
int /*<<< orphan*/ strasp_free(char **);
int strlen(char *);
int main(int argc, char **argv) {
  char string[(8192 >> 4)];
  char *str_ptr = string;
  const char *delim = "";
  char **myargv;
  char **tmp_array;
  if (argc != 2) {
    printf("usage: strasp \"delim\"\n");
    return 1;
  }
  delim = argv[1];
  while (1) {
    printf("strasp> ");
    if ((str_ptr = fgets(str_ptr, 8192, stdin)) == NULL) {
      perror("gets");
      return 1;
    }
    str_ptr[strlen(str_ptr) - 1] = '\0';
    myargv = strasp(str_ptr, delim);
    if (myargv == NULL)
      continue;
    tmp_array = myargv;
    while (tmp_array && *tmp_array)
      printf("%s\n", *(tmp_array++));
    strasp_free(myargv);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    0xe88(%rip),%rax
mov    %rax,-0x220(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b9 <main+0x59>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x19a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x220(%rbp)
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x218(%rbp),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    $0x2000,%esi
call   1060 <fgets@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jne    1219 <main+0xb9>
lea    0xe18(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x19a>
mov    -0x218(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x238(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x218(%rbp),%rdi
mov    -0x220(%rbp),%rsi
call   1070 <strasp@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    1273 <main+0x113>
jmp    11c8 <main+0x68>
mov    -0x228(%rbp),%rax
mov    %rax,-0x230(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x230(%rbp)
mov    %al,-0x239(%rbp)
je     12ab <main+0x14b>
mov    -0x230(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x239(%rbp)
mov    -0x239(%rbp),%al
test   $0x1,%al
jne    12be <main+0x15e>
jmp    12e9 <main+0x189>
mov    -0x230(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x230(%rbp)
mov    (%rax),%rsi
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1281 <main+0x121>
mov    -0x228(%rbp),%rdi
call   1030 <strasp_free@plt>
jmp    11c8 <main+0x68>
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
cmp    $0x2,%edi
je     11a9 <main+0x39>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsi),%r15
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e26(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
mov    $0x2000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11e6 <main+0x76>
lea    0xe2a(%rip),%rdi
call   1090 <perror@plt>
jmp    1192 <main+0x22>
mov    %rax,%rbx
lea    0xe10(%rip),%r14
jmp    122b <main+0xbb>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <strasp_free@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1070 <fgets@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d8 <main+0x68>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strasp@plt>
test   %rax,%rax
je     1208 <main+0x98>
mov    %rax,%r12
mov    (%rax),%rdi
test   %rdi,%rdi
je     1200 <main+0x90>
mov    %r12,%rbp
add    $0x8,%rbp
nopl   0x0(%rax)
call   1040 <puts@plt>
mov    0x0(%rbp),%rdi
add    $0x8,%rbp
test   %rdi,%rdi
jne    1260 <main+0xf0>
jmp    1200 <main+0x90>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [23 x i8] c"usage: strasp \22delim\22\0A\00"
@.str.2 = [9 x i8] c"strasp> \00"
@stdin = global i32 0
@.str.3 = [5 x i8] c"gets\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
store i8* %11, i8** %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %60
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %8
br label %20
20: ; preds = %16, %40, %57
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = load i8*, i8** %7
%23 = load i32, i32* @stdin
%24 = call i8* @fgets(i8* %22, i32 8192, i32 %23)
store i8* %24, i8** %7
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %60
28: ; preds = %20
%29 = load i8*, i8** %7
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %7
%36 = load i8*, i8** %8
%37 = call i8** @strasp(i8* %35, i8* %36)
store i8** %37, i8*** %9
%38 = load i8**, i8*** %9
%39 = icmp eq i8** %38, null
br i1 %39, label %40, label %41
40: ; preds = %28
br label %20
41: ; preds = %28
%42 = load i8**, i8*** %9
store i8** %42, i8*** %10
br label %43
43: ; preds = %52, %41
%44 = load i8**, i8*** %10
%45 = icmp ne i8** %44, null
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i8**, i8*** %10
%48 = load i8*, i8** %47
%49 = icmp ne i8* %48, null
br label %50
50: ; preds = %46, %43
%51 = phi i1 [ false, %43 ], [ %49, %46 ]
br i1 %51, label %52, label %57
52: ; preds = %50
%53 = load i8**, i8*** %10
%54 = getelementptr inbounds i8*, i8** %53, i32 1
store i8** %54, i8*** %10
%55 = load i8*, i8** %53
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %43
57: ; preds = %50
%58 = load i8**, i8*** %9
%59 = call i32 @strasp_free(i8** %58)
br label %20
60: ; preds = %26, %14
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c"strasp> \00"
@stdin = global i32 0
@.str.3 = [5 x i8] c"gets\00"
@str = [22 x i8] c"usage: strasp \22delim\22\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %42
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @stdin
%13 = call i8* @fgets(i8* %4, i32 8192, i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %37, %8
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %42
17: ; preds = %8, %37
%18 = phi i8* [ %40, %37 ], [ %13, %8 ]
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 0, i8* %22
%23 = call i8** @strasp(i8* %18, i8* %10)
%24 = icmp eq i8** %23, null
br i1 %24, label %37, label %25
25: ; preds = %17
%26 = load i8*, i8** %23
%27 = icmp eq i8* %26, null
br i1 %27, label %35, label %28
28: ; preds = %25, %28
%29 = phi i8* [ %33, %28 ], [ %26, %25 ]
%30 = phi i8** [ %31, %28 ], [ %23, %25 ]
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = call i32 @puts(i8* %29)
%33 = load i8*, i8** %31
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %28
35: ; preds = %28, %25
%36 = call i32 @strasp_free(i8** %23)
br label %37
37: ; preds = %35, %17
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @stdin
%40 = call i8* @fgets(i8* %18, i32 8192, i32 %39)
%41 = icmp eq i8* %40, null
br i1 %41, label %15, label %17
42: ; preds = %15, %6
ret i32 1
}