#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*/ SEEK_END;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int write(int, char *, int);
void parse_file(char *file_string, int output_file) {
  int bytes = 0;
  char *write_string;
  char *returned = NULL;
  write_string = malloc(sizeof(char) * (strlen(file_string) + 1));
  bytes = write(output_file, "echo \"\n", 7);
  do {
    memset(write_string, '\0', sizeof(char) * (strlen(file_string) + 1));
    if (returned == NULL) {
      returned = strtok(file_string, "\"");
    } else {
      returned = strtok(NULL, "\"");
    }
    if (returned != NULL) {
      strcpy(write_string, returned);
      bytes = write(output_file, write_string, strlen(write_string));
      bytes = write(output_file, "\\", 1);
      bytes = write(output_file, "\"", 1);
    }
  } while (returned != NULL);
  lseek(output_file, -2, SEEK_END);
  bytes = write(output_file, "\";", 2);
  free(write_string);
}


x86 assembly (clang, -O0):
<parse_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe3b(%rip),%rsi
mov    $0x7,%edx
call   1050 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1080 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
jne    121d <parse_file+0x9d>
mov    -0x8(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1231 <parse_file+0xb1>
xor    %eax,%eax
mov    %eax,%edi
lea    0xde0(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     129f <parse_file+0x11f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    0xd8f(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    0xd76(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %eax,-0x10(%rbp)
jmp    12a4 <parse_file+0x124>
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <parse_file+0x52>
mov    -0xc(%rbp),%edi
mov    0x2d2f(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1070 <lseek@plt>
mov    -0xc(%rbp),%edi
lea    0xd3d(%rip),%rsi
mov    $0x2,%edx
call   1050 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %rdi,%r14
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xe58(%rip),%rsi
mov    %r13d,%edi
mov    $0x7,%edx
call   1050 <write@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe37(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1271 <parse_file+0xf1>
mov    %rax,%rbp
lea    0xe1e(%rip),%r15
lea    0xe15(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
test   %rbp,%rbp
mov    $0x0,%edi
cmove  %r14,%rdi
mov    %r12,%rsi
call   10a0 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1200 <parse_file+0x80>
mov    0x2d70(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    $0xfffffffe,%esi
call   1070 <lseek@plt>
lea    0xd7e(%rip),%rsi
mov    %r13d,%edi
mov    $0x2,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"echo \22\0A\00"
@.str.1 = [2 x i8] c"\22\00"
@.str.2 = [2 x i8] c"\\\00"
@SEEK_END = global i32 0
@.str.3 = [3 x i8] c"\22;\00"
define void @parse_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i8* null, i8** %7
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 1, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %6
%15 = load i32, i32* %4
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
store i32 %16, i32* %5
br label %17
17: ; preds = %50, %2
%18 = load i8*, i8** %6
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 1, %22
%24 = trunc i64 %23 to i32
%25 = call i32 @memset(i8* %18, i8 signext 0, i32 %24)
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = load i8*, i8** %3
%30 = call i8* @strtok(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %7
br label %33
31: ; preds = %17
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %32, i8** %7
br label %33
33: ; preds = %31, %28
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %49
36: ; preds = %33
%37 = load i8*, i8** %6
%38 = load i8*, i8** %7
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = load i32, i32* %4
%41 = load i8*, i8** %6
%42 = load i8*, i8** %6
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @write(i32 %40, i8* %41, i32 %43)
store i32 %44, i32* %5
%45 = load i32, i32* %4
%46 = call i32 @write(i32 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %46, i32* %5
%47 = load i32, i32* %4
%48 = call i32 @write(i32 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 %48, i32* %5
br label %49
49: ; preds = %36, %33
br label %50
50: ; preds = %49
%51 = load i8*, i8** %7
%52 = icmp ne i8* %51, null
br i1 %52, label %17, label %53
53: ; preds = %50
%54 = load i32, i32* %4
%55 = load i32, i32* @SEEK_END
%56 = call i32 @lseek(i32 %54, i32 -2, i32 %55)
%57 = load i32, i32* %4
%58 = call i32 @write(i32 %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
store i32 %58, i32* %5
%59 = load i8*, i8** %6
%60 = call i32 @free(i8* %59)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"echo \22\0A\00"
@.str.1 = [2 x i8] c"\22\00"
@.str.2 = [2 x i8] c"\\\00"
@SEEK_END = global i32 0
@.str.3 = [3 x i8] c"\22;\00"
define void @parse_file(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, 1
%9 = tail call i32 @memset(i8* %5, i8 signext 0, i32 %8)
%10 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %26, label %12
12: ; preds = %2, %12
%13 = phi i8* [ %24, %12 ], [ %10, %2 ]
%14 = tail call i32 @strcpy(i8* %5, i8* %13)
%15 = tail call i32 @strlen(i8* %5)
%16 = tail call i32 @write(i32 %1, i8* %5, i32 %15)
%17 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%18 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%19 = tail call i32 @strlen(i8* %0)
%20 = add nsw i32 %19, 1
%21 = tail call i32 @memset(i8* %5, i8 signext 0, i32 %20)
%22 = icmp eq i8* %13, null
%23 = select i1 %22, i8* %0, i8* null
%24 = tail call i8* @strtok(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %12
26: ; preds = %12, %2
%27 = load i32, i32* @SEEK_END
%28 = tail call i32 @lseek(i32 %1, i32 -2, i32 %27)
%29 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%30 = tail call i32 @free(i8* %5)
ret void
}