#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*/ brackrange(char *, int *, int *, char **);
int /*<<< orphan*/ malloc(int);
char *memcheck(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strcspn(char *, char *);
char *getstring(char *cp, char **endp) {
  int len;
  int start;
  char *str;
  if (!brackrange(cp, &start, &len, endp)) {
    start = 0;
    len = strcspn(cp, " \t\n,;");
    if (endp)
      *endp = cp + len;
  }
  str = memcheck(malloc(len + 1));
  memcpy(str, cp + start, len);
  str[len] = 0;
  return str;
}


x86 assembly (clang, -O0):
<getstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <brackrange@plt>
cmp    $0x0,%eax
jne    11ba <getstring+0x6a>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b5 <getstring+0x65>
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11ba <getstring+0x6a>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %eax,%edi
call   1070 <memcheck@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstring>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rcx
call   1050 <brackrange@plt>
test   %eax,%eax
je     117b <getstring+0x2b>
mov    0x8(%rsp),%edi
jmp    11a6 <getstring+0x56>
movl   $0x0,0xc(%rsp)
lea    0xe76(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcspn@plt>
mov    %eax,%edi
mov    %eax,0x8(%rsp)
test   %r14,%r14
je     11a6 <getstring+0x56>
movslq %edi,%rax
add    %r15,%rax
mov    %rax,(%r14)
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %eax,%edi
call   1070 <memcheck@plt>
mov    %rax,%rbx
movslq 0xc(%rsp),%rax
add    %rax,%r15
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
movslq 0x8(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c" \09\0A,;\00"
define i8* @getstring(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
%8 = load i8*, i8** %3
%9 = load i8**, i8*** %4
%10 = call i32 @brackrange(i8* %8, i32* %6, i32* %5, i8** %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %2
store i32 0, i32* %6
%13 = load i8*, i8** %3
%14 = call i32 @strcspn(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %5
%15 = load i8**, i8*** %4
%16 = icmp ne i8** %15, null
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8**, i8*** %4
store i8* %21, i8** %22
br label %23
23: ; preds = %17, %12
br label %24
24: ; preds = %23, %2
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
%27 = call i32 @malloc(i32 %26)
%28 = call i8* @memcheck(i32 %27)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = load i8*, i8** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i32, i32* %5
%35 = call i32 @memcpy(i8* %29, i8* %33, i32 %34)
%36 = load i8*, i8** %7
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %7
ret i8* %40
}

LLVM IR (-O2):
@.str = [6 x i8] c" \09\0A,;\00"
define i8* @getstring(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @brackrange(i8* %0, i32* %4, i32* %3, i8** %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = load i32, i32* %3
br label %17
11: ; preds = %2
store i32 0, i32* %4
%12 = call i32 @strcspn(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %3
%13 = icmp eq i8** %1, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8* %16, i8** %1
br label %17
17: ; preds = %9, %11, %14
%18 = phi i32 [ %10, %9 ], [ %12, %11 ], [ %12, %14 ]
%19 = add nsw i32 %18, 1
%20 = call i32 @malloc(i32 %19)
%21 = call i8* @memcheck(i32 %20)
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i32, i32* %3
%26 = call i32 @memcpy(i8* %21, i8* %24, i32 %25)
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %21, i64 %28
store i8 0, i8* %29
ret i8* %21
}