#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 char uint8_t;
typedef int int8_t;

/* Variables and functions */
int /*<<< orphan*/ strncpy(char *, char *, int);
int8_t parse_script(uint8_t *text, void *buf) {
  uint8_t *dest = (uint8_t *)buf;
  dest[512 - 1] = '\0';
  strncpy(dest, text, 512);
  if (dest[512 - 1] != '\0') {
    dest[512 - 1] = '\0';
    return -1;
  }
  while (*dest != '\0') {
    if (*dest == '\\') {
      *dest = '\n';
    }
    dest++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,0x1ff(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movsbl 0x1ff(%rax),%eax
cmp    $0x0,%eax
je     1170 <parse_script+0x60>
mov    -0x20(%rbp),%rax
movb   $0x0,0x1ff(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <parse_script+0xa4>
jmp    1175 <parse_script+0x65>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ad <parse_script+0x9d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    119c <parse_script+0x8c>
mov    -0x20(%rbp),%rax
movb   $0xa,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1175 <parse_script+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_script>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rsi
movb   $0x0,0x1ff(%rbx)
mov    %rbx,%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0x1ff(%rbx)
je     1157 <parse_script+0x47>
movb   $0x0,0x1ff(%rbx)
mov    $0xffffffff,%eax
pop    %rbx
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0xa,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1150 <parse_script+0x40>
test   %al,%al
jne    1153 <parse_script+0x43>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @parse_script(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = getelementptr inbounds i8, i8* %8, i64 511
store i8 0, i8* %9
%10 = load i8*, i8** %6
%11 = load i8*, i8** %4
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 512)
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i64 511
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 511
store i8 0, i8* %20
store i32 -1, i32* %3
br label %38
21: ; preds = %2
br label %22
22: ; preds = %34, %21
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 92
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = load i8*, i8** %6
store i8 10, i8* %33
br label %34
34: ; preds = %32, %27
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %6
br label %22
37: ; preds = %22
store i32 0, i32* %3
br label %38
38: ; preds = %37, %18
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @parse_script(i8* %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 511
store i8 0, i8* %3
%4 = tail call i32 @strncpy(i8* %1, i8* %0, i32 512)
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %2
store i8 0, i8* %3
br label %14
8: ; preds = %2, %12
%9 = phi i8* [ %13, %12 ], [ %1, %2 ]
%10 = load i8, i8* %9
switch i8 %10, label %12 [
i8 0, label %14
i8 92, label %11
]
11: ; preds = %8
store i8 10, i8* %9
br label %12
12: ; preds = %8, %11
%13 = getelementptr inbounds i8, i8* %9, i64 1
br label %8
14: ; preds = %8, %7
%15 = phi i32 [ -1, %7 ], [ 0, %8 ]
ret i32 %15
}