#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*/ ispunct(unsigned char);
int /*<<< orphan*/ malloc(int);
char *memcheck(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strcspn(char *, char *);
char *getstring_fn(char *cp, char **endp) {
  char endstr[4];
  int len;
  char *str;
  switch (*cp) {
  case '<':
  case ':':
    return NULL;
  }
  if (!ispunct((unsigned char)*cp)) {
    return NULL;
  }
  endstr[0] = *cp;
  endstr[1] = '\n';
  endstr[2] = '\0';
  cp++;
  len = strcspn(cp, endstr);
  if (endp)
    *endp = cp + len + 1;
  str = memcheck(malloc(len + 1));
  memcpy(str, cp, len);
  str[len] = 0;
  return str;
}


x86 assembly (clang, -O0):
<getstring_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x3a,%eax
je     1189 <getstring_fn+0x39>
jmp    1178 <getstring_fn+0x28>
mov    -0x2c(%rbp),%eax
sub    $0x3c,%eax
jne    1196 <getstring_fn+0x46>
jmp    1189 <getstring_fn+0x39>
movq   $0x0,-0x8(%rbp)
jmp    1240 <getstring_fn+0xf0>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <ispunct@plt>
cmp    $0x0,%eax
jne    11b8 <getstring_fn+0x68>
movq   $0x0,-0x8(%rbp)
jmp    1240 <getstring_fn+0xf0>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1c(%rbp)
movb   $0xa,-0x1b(%rbp)
movb   $0x0,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1206 <getstring_fn+0xb6>
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rax
add    %rax,%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %eax,%edi
call   1070 <memcheck@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstring_fn>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%al
movsbl %al,%ecx
xor    %ebx,%ebx
cmp    $0x3a,%ecx
je     11d8 <getstring_fn+0x88>
cmp    $0x3c,%ecx
je     11d8 <getstring_fn+0x88>
mov    %rsi,%r14
mov    %rdi,%r12
movzbl %al,%edi
call   1030 <ispunct@plt>
test   %eax,%eax
je     11d6 <getstring_fn+0x86>
mov    (%r12),%al
mov    %al,0x4(%rsp)
movw   $0xa,0x5(%rsp)
add    $0x1,%r12
lea    0x4(%rsp),%rsi
mov    %r12,%rdi
call   1040 <strcspn@plt>
movslq %eax,%r15
test   %r14,%r14
je     11ae <getstring_fn+0x5e>
lea    (%r12,%r15,1),%rax
add    $0x1,%rax
mov    %rax,(%r14)
lea    0x1(%r15),%edi
call   1060 <malloc@plt>
mov    %eax,%edi
call   1070 <memcheck@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    11d8 <getstring_fn+0x88>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @getstring_fn(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %13 [
i32 60, label %12
i32 58, label %12
]
12: ; preds = %2, %2
store i8* null, i8** %3
br label %53
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = call i32 @ispunct(i8 zeroext %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %13
store i8* null, i8** %3
br label %53
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 %21, i8* %22
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
store i8 10, i8* %23
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
store i8 0, i8* %24
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%29 = call i32 @strcspn(i8* %27, i8* %28)
store i32 %29, i32* %7
%30 = load i8**, i8*** %5
%31 = icmp ne i8** %30, null
br i1 %31, label %32, label %39
32: ; preds = %19
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8**, i8*** %5
store i8* %37, i8** %38
br label %39
39: ; preds = %32, %19
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
%42 = call i32 @malloc(i32 %41)
%43 = call i8* @memcheck(i32 %42)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = load i8*, i8** %4
%46 = load i32, i32* %7
%47 = call i32 @memcpy(i8* %44, i8* %45, i32 %46)
%48 = load i8*, i8** %8
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %8
store i8* %52, i8** %3
br label %53
53: ; preds = %39, %18, %12
%54 = load i8*, i8** %3
ret i8* %54
}

LLVM IR (-O2):
define i8* @getstring_fn(i8* %0, i8** writeonly %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
%6 = sext i8 %5 to i32
switch i32 %6, label %7 [
i32 60, label %27
i32 58, label %27
]
7: ; preds = %2
%8 = tail call i32 @ispunct(i8 zeroext %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %7
%11 = load i8, i8* %0
store i8 %11, i8* %4
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 10, i8* %12
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
store i8 0, i8* %13
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = call i32 @strcspn(i8* %14, i8* %4)
%16 = icmp eq i8** %1, null
%17 = sext i32 %15 to i64
br i1 %16, label %21, label %18
18: ; preds = %10
%19 = getelementptr inbounds i8, i8* %14, i64 %17
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %1
br label %21
21: ; preds = %10, %18
%22 = add nsw i32 %15, 1
%23 = tail call i32 @malloc(i32 %22)
%24 = tail call i8* @memcheck(i32 %23)
%25 = tail call i32 @memcpy(i8* %24, i8* %14, i32 %15)
%26 = getelementptr inbounds i8, i8* %24, i64 %17
store i8 0, i8* %26
br label %27
27: ; preds = %7, %2, %2, %21
%28 = phi i8* [ %24, %21 ], [ null, %2 ], [ null, %2 ], [ null, %7 ]
ret i8* %28
}