#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 *duplicate_string(char const *);
int /*<<< orphan*/ error_exit(int, char *);
int /*<<< orphan*/ memmove(char *, char *, int);
char *realloc(char *, int);
int strlen(char *);
char *strstr(char *, char *);
char *get_string_argument(const char *argument) {
  if (*argument != '"')
    error_exit(1, "unquoted string");
  char *result = duplicate_string(argument + 1);
  unsigned length = strlen(result) - 1;
  if (result[length] != '"')
    error_exit(1, "unquoted string");
  result[length] = 0;
  char *pos = result;
  while (pos = strstr(pos, "\"\"")) {
    pos++;
    memmove(pos, pos + 1, strlen(pos));
  }
  result = realloc(result, strlen(result) + 1);
  return result;
}


x86 assembly (clang, -O0):
<get_string_argument>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     118d <get_string_argument+0x2d>
mov    $0x1,%edi
lea    0xe78(%rip),%rsi
call   1050 <error_exit@plt>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <duplicate_string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
je     11d2 <get_string_argument+0x72>
mov    $0x1,%edi
lea    0xe33(%rip),%rsi
call   1050 <error_exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1240 <get_string_argument+0xe0>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1070 <memmove@plt>
jmp    11e5 <get_string_argument+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_string_argument>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x22,(%rdi)
je     1181 <get_string_argument+0x21>
lea    0xe89(%rip),%rsi
mov    $0x1,%edi
call   1050 <error_exit@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <duplicate_string@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
add    $0xffffffff,%ebx
cmpb   $0x22,(%r14,%rbx,1)
je     11b5 <get_string_argument+0x55>
lea    0xe55(%rip),%rsi
mov    $0x1,%edi
call   1050 <error_exit@plt>
movb   $0x0,(%r14,%rbx,1)
lea    0xe4f(%rip),%rsi
mov    %r14,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     1210 <get_string_argument+0xb0>
mov    %rax,%rbx
lea    0xe38(%rip),%r15
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r12
add    $0x2,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <memmove@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e0 <get_string_argument+0x80>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <realloc@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"unquoted string\00"
@.str.1 = [3 x i8] c"\22\22\00"
define i8* @get_string_argument(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 34
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @error_exit(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i8* @duplicate_string(i8* %14)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %4
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 34
br i1 %25, label %26, label %28
26: ; preds = %12
%27 = call i32 @error_exit(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %12
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %3
store i8* %33, i8** %5
br label %34
34: ; preds = %38, %28
%35 = load i8*, i8** %5
%36 = call i8* @strstr(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %36, i8** %5
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
%41 = load i8*, i8** %5
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @memmove(i8* %41, i8* %43, i32 %45)
br label %34
47: ; preds = %34
%48 = load i8*, i8** %3
%49 = load i8*, i8** %3
%50 = call i32 @strlen(i8* %49)
%51 = add nsw i32 %50, 1
%52 = call i8* @realloc(i8* %48, i32 %51)
store i8* %52, i8** %3
%53 = load i8*, i8** %3
ret i8* %53
}

LLVM IR (-O2):
@.str = [16 x i8] c"unquoted string\00"
@.str.1 = [3 x i8] c"\22\22\00"
define i8* @get_string_argument(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 34
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @error_exit(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = tail call i8* @duplicate_string(i8* %7)
%9 = tail call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 34
br i1 %14, label %17, label %15
15: ; preds = %6
%16 = tail call i32 @error_exit(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %6
store i8 0, i8* %12
%18 = tail call i8* @strstr(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %28, label %20
20: ; preds = %17, %20
%21 = phi i8* [ %26, %20 ], [ %18, %17 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = getelementptr inbounds i8, i8* %21, i64 2
%24 = tail call i32 @strlen(i8* %22)
%25 = tail call i32 @memmove(i8* %22, i8* %23, i32 %24)
%26 = tail call i8* @strstr(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %20
28: ; preds = %20, %17
%29 = tail call i32 @strlen(i8* %8)
%30 = add nsw i32 %29, 1
%31 = tail call i8* @realloc(i8* %8, i32 %30)
ret i8* %31
}