#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 */
typedef int /*<<< orphan*/ token;

/* Variables and functions */
int /*<<< orphan*/ lex(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ parse(char *, char *);
void lex_string(char *str) {
  char token[20];
  char *toktype;
  token[0] = '"';
  int i = 1;
  str++;
  while ((*str != '\"') && *str != '\0' && i < 20) {
    token[i] = *str;
    i++;
    str++;
  }
  token[i] = '"';
  token[i + 1] = '\0';
  str++;
  toktype = "String";
  parse(token, toktype);
  memset(&token[0], 0, sizeof(token));
  lex(str);
}


x86 assembly (clang, -O0):
<lex_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x22,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x22,%ecx
mov    %al,-0x2d(%rbp)
je     1187 <lex_string+0x57>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
je     1187 <lex_string+0x57>
cmpl   $0x14,-0x2c(%rbp)
setl   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1197 <lex_string+0x67>
jmp    11bf <lex_string+0x8f>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1153 <lex_string+0x23>
movslq -0x2c(%rbp),%rax
movb   $0x22,-0x20(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x20(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
lea    0xe18(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <parse@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1030 <lex@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lex_string>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movb   $0x22,(%rsp)
mov    0x1(%rdi),%cl
mov    $0x1,%eax
test   %cl,%cl
je     1189 <lex_string+0x59>
cmp    $0x22,%cl
je     1189 <lex_string+0x59>
add    $0x1,%rbx
mov    $0x1,%edx
mov    $0x2,%eax
mov    %rbx,%rdi
mov    %rdi,%rbx
mov    %cl,(%rsp,%rdx,1)
movzbl 0x1(%rdi),%ecx
cmp    $0x22,%cl
je     1189 <lex_string+0x59>
lea    0x1(%rdx),%rsi
test   %cl,%cl
je     1187 <lex_string+0x57>
lea    0x1(%rbx),%rdi
add    $0x1,%eax
cmp    $0x12,%rdx
mov    %rsi,%rdx
jbe    1160 <lex_string+0x30>
mov    %esi,%eax
mov    %eax,%eax
movw   $0x22,(%rsp,%rax,1)
add    $0x2,%rbx
lea    0xe64(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <parse@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <lex@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"String\00"
define void @lex_string(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
store i8 34, i8* %3
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
switch i8 %5, label %10 [
i8 34, label %23
i8 0, label %23
]
6: ; preds = %10
%7 = icmp ne i8 %19, 0
%8 = icmp ult i64 %14, 19
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %21
10: ; preds = %1, %6
%11 = phi i32 [ %17, %6 ], [ 1, %1 ]
%12 = phi i8* [ %18, %6 ], [ %4, %1 ]
%13 = phi i8 [ %19, %6 ], [ %5, %1 ]
%14 = phi i64 [ %16, %6 ], [ 1, %1 ]
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %14
store i8 %13, i8* %15
%16 = add nuw nsw i64 %14, 1
%17 = add nuw nsw i32 %11, 1
%18 = getelementptr inbounds i8, i8* %12, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 34
br i1 %20, label %23, label %6
21: ; preds = %6
%22 = trunc i64 %16 to i32
br label %23
23: ; preds = %10, %21, %1, %1
%24 = phi i8* [ %0, %1 ], [ %12, %21 ], [ %0, %1 ], [ %12, %10 ]
%25 = phi i32 [ 1, %1 ], [ %22, %21 ], [ 1, %1 ], [ %17, %10 ]
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %26
store i8 34, i8* %27
%28 = add nuw nsw i32 %25, 1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds i8, i8* %24, i64 2
%32 = call i32 @parse(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @memset(i8* %3, i32 0, i32 20)
%34 = call i32 @lex(i8* %31)
ret void
}