#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*/ memcpy(char *, char *, int);
char *xmalloc(int);
char *getstring(char *b) {
  char *s;
  int i;
  if (*b++ != '"')
    return NULL;
  for (i = 0; !(b[i] == '"' && b[i - 1] != '\\'); i++) {
    if (!b[i])
      return NULL;
  }
  s = xmalloc(i + 1);
  memcpy(b, s, i);
  s[i] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<getstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x22,%eax
je     1154 <getstring+0x34>
movq   $0x0,-0x8(%rbp)
jmp    1206 <getstring+0xe6>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x22,%ecx
mov    %al,-0x1d(%rbp)
jne    118f <getstring+0x6f>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    11a1 <getstring+0x81>
jmp    11d3 <getstring+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11c0 <getstring+0xa0>
movq   $0x0,-0x8(%rbp)
jmp    1206 <getstring+0xe6>
jmp    11c5 <getstring+0xa5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <getstring+0x3b>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1030 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmpb   $0x22,(%rdi)
jne    1159 <getstring+0x39>
mov    %rdi,%r14
add    $0x1,%r14
xor    %ebx,%ebx
jmp    114c <getstring+0x2c>
nopl   0x0(%rax,%rax,1)
cmpb   $0x5c,-0x1(%r14,%rbx,1)
jne    115e <getstring+0x3e>
add    $0x1,%rbx
movzbl (%r14,%rbx,1),%eax
cmp    $0x22,%al
je     1140 <getstring+0x20>
test   %al,%al
jne    1148 <getstring+0x28>
xor    %r15d,%r15d
jmp    117e <getstring+0x5e>
mov    %ebx,%r12d
lea    0x1(%rbx),%edi
call   1030 <xmalloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @getstring(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 34
br i1 %4, label %5, label %22
5: ; preds = %1, %13
%6 = phi i64 [ %14, %13 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %13 [
i8 34, label %9
i8 0, label %22
]
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 92
br i1 %12, label %13, label %15
13: ; preds = %5, %9
%14 = add nuw i64 %6, 1
br label %5
15: ; preds = %9
%16 = trunc i64 %6 to i32
%17 = and i64 %6, 4294967295
%18 = add nuw nsw i32 %16, 1
%19 = tail call i8* @xmalloc(i32 %18)
%20 = tail call i32 @memcpy(i8* %2, i8* %19, i32 %16)
%21 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 0, i8* %21
br label %22
22: ; preds = %5, %1, %15
%23 = phi i8* [ %19, %15 ], [ null, %1 ], [ null, %5 ]
ret i8* %23
}