#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 /*<<< orphan*/ strcat(char *, char *);
char *strtok_r(char *, char *, char **);
char *getstring(char *str, char *delims, char **curpos) {
  char *rc = NULL;
  static char buf[128];
  buf[0] = '\0';
  while (**curpos == ' ')
    (*curpos)++;
  if (**curpos == '\"') {
    if (*((*curpos) + 1) == '\"')
      (*curpos) += 2;
    else {
      strcat(buf, strtok_r(str, "\"", curpos));
      while (**curpos == '\"') {
        strcat(buf, "\"");
        strcat(buf, strtok_r(str, "\"", curpos));
      }
    }
    rc = buf;
  } else
    rc = strtok_r(str, delims, curpos);
  return rc;
}


x86 assembly (clang, -O0):
<getstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x0,0x2efd(%rip)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1169 <getstring+0x49>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1143 <getstring+0x23>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1229 <getstring+0x109>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x22,%eax
jne    11a3 <getstring+0x83>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x2,%rcx
mov    %rcx,(%rax)
jmp    1219 <getstring+0xf9>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1030 <strtok_r@plt>
mov    %rax,%rsi
lea    0x2e7f(%rip),%rdi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1214 <getstring+0xf4>
lea    0x2e60(%rip),%rdi
lea    0xe19(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe05(%rip),%rsi
call   1030 <strtok_r@plt>
mov    %rax,%rsi
lea    0x2e36(%rip),%rdi
call   1040 <strcat@plt>
jmp    11c6 <getstring+0xa6>
jmp    1219 <getstring+0xf9>
lea    0x2e20(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    123e <getstring+0x11e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
movb   $0x0,0x2f0b(%rip)
mov    (%rdx),%rax
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
movzbl -0x1(%rax),%ecx
cmp    $0x20,%cl
jne    1152 <getstring+0x32>
mov    %rax,(%rbx)
jmp    1140 <getstring+0x20>
cmp    $0x22,%cl
jne    1168 <getstring+0x48>
cmpb   $0x22,(%rax)
jne    117e <getstring+0x5e>
add    $0x1,%rax
mov    %rax,(%rbx)
jmp    11ec <getstring+0xcc>
mov    %r14,%rdi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strtok_r@plt>
lea    0xe7b(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <strtok_r@plt>
lea    0x2ea9(%rip),%rdi
mov    %rax,%rsi
call   1040 <strcat@plt>
mov    (%rbx),%rax
cmpb   $0x22,(%rax)
jne    11ec <getstring+0xcc>
lea    0x2e92(%rip),%r15
lea    0xe4b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <strtok_r@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <strcat@plt>
mov    (%rbx),%rax
cmpb   $0x22,(%rax)
je     11c0 <getstring+0xa0>
lea    0x2e4d(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@getstring.buf = internal global [128 x i8] zeroinitializer
@.str = [2 x i8] c"\22\00"
define i8* @getstring(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
store i8* null, i8** %7
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0)
br label %8
8: ; preds = %14, %3
%9 = load i8**, i8*** %6
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 32
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = load i8**, i8*** %6
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %15
br label %8
18: ; preds = %8
%19 = load i8**, i8*** %6
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 34
br i1 %23, label %24, label %54
24: ; preds = %18
%25 = load i8**, i8*** %6
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 34
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i8**, i8*** %6
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %32
br label %53
35: ; preds = %24
%36 = load i8*, i8** %4
%37 = load i8**, i8*** %6
%38 = call i8* @strtok_r(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %37)
%39 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %46, %35
%41 = load i8**, i8*** %6
%42 = load i8*, i8** %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 34
br i1 %45, label %46, label %52
46: ; preds = %40
%47 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%48 = load i8*, i8** %4
%49 = load i8**, i8*** %6
%50 = call i8* @strtok_r(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %49)
%51 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), i8* %50)
br label %40
52: ; preds = %40
br label %53
53: ; preds = %52, %31
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), i8** %7
br label %59
54: ; preds = %18
%55 = load i8*, i8** %4
%56 = load i8*, i8** %5
%57 = load i8**, i8*** %6
%58 = call i8* @strtok_r(i8* %55, i8* %56, i8** %57)
store i8* %58, i8** %7
br label %59
59: ; preds = %54, %53
%60 = load i8*, i8** %7
ret i8* %60
}

LLVM IR (-O2):
@getstring.buf = internal global [128 x i8] zeroinitializer
@.str = [2 x i8] c"\22\00"
define i8* @getstring(i8* %0, i8* nocapture %1, i8** %2) {
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0)
%4 = load i8*, i8** %2
br label %5
5: ; preds = %8, %3
%6 = phi i8* [ %9, %8 ], [ %4, %3 ]
%7 = load i8, i8* %6
switch i8 %7, label %29 [
i8 32, label %8
i8 34, label %10
]
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %9, i8** %2
br label %5
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 34
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %6, i64 2
store i8* %15, i8** %2
br label %31
16: ; preds = %10
%17 = tail call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%18 = tail call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 34
br i1 %21, label %22, label %31
22: ; preds = %16, %22
%23 = tail call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = tail call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%25 = tail call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %2
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 34
br i1 %28, label %22, label %31
29: ; preds = %5
%30 = tail call i8* @strtok_r(i8* %0, i8* %1, i8** %2)
br label %31
31: ; preds = %22, %16, %14, %29
%32 = phi i8* [ %30, %29 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), %14 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), %16 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @getstring.buf, i64 0, i64 0), %22 ]
ret i8* %32
}