#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*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *prescan(char const *s, char const *szExeName, int *bBegin, int *bEnd) {
  char *retString = NULL;
  int len;
  *bBegin = *bEnd = 0;
  len = strlen(s);
  if (len <= 0) {
    fprintf(stderr, "Uso: %s regexp\nCon regexp stringa non vuota.\n",
            szExeName);
    return NULL;
  }
  if (s[0] == '^')
    *bBegin = 1;
  if (s[len - 1] == '$')
    *bEnd = 1;
  if (s[len - 1] == '\\') {
    fprintf(stderr, "Errore: Carattere \"backslash\" alla fine della riga\n");
    return NULL;
  }
  if (len >= 2 && s[len - 2] == '\\')
    *bEnd = 0;
  retString = (char *)malloc(sizeof(char) * (len + 1));
  if (!retString) {
    fprintf(stderr, "Errore prescan: memoria insufficiente.\n");
    return NULL;
  }
  retString[0] = '\0';
  if (*bBegin)
    strncpy(retString, s + 1, len + 1);
  else
    strncpy(retString, s, len + 1);
  len = strlen(retString);
  if (*bEnd)
    retString[len - 1] = '\0';
  return retString;
}


x86 assembly (clang, -O0):
<prescan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jg     11b2 <prescan+0x72>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1317 <prescan+0x1d7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    11cc <prescan+0x8c>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
jne    11f0 <prescan+0xb0>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    122e <prescan+0xee>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1317 <prescan+0x1d7>
cmpl   $0x2,-0x34(%rbp)
jl     125c <prescan+0x11c>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    125c <prescan+0x11c>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12a2 <prescan+0x162>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1317 <prescan+0x1d7>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     12d2 <prescan+0x192>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
jmp    12e5 <prescan+0x1a5>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     130f <prescan+0x1cf>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prescan>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r13
movl   $0x0,(%rcx)
movl   $0x0,(%rdx)
call   1040 <strlen@plt>
test   %eax,%eax
jle    11b0 <prescan+0x70>
mov    %eax,%ebx
cmpb   $0x5e,0x0(%r13)
jne    117d <prescan+0x3d>
movl   $0x1,(%r12)
lea    -0x1(%rbx),%eax
mov    0x0(%r13,%rax,1),%cl
cmp    $0x24,%cl
jne    1196 <prescan+0x56>
movl   $0x1,(%r14)
mov    0x0(%r13,%rax,1),%cl
cmp    $0x5c,%cl
jne    11cf <prescan+0x8f>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
jmp    1239 <prescan+0xf9>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
xor    %r15d,%r15d
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1243 <prescan+0x103>
cmp    $0x2,%ebx
jb     11e6 <prescan+0xa6>
lea    -0x2(%rbx),%eax
cmpb   $0x5c,0x0(%r13,%rax,1)
jne    11e6 <prescan+0xa6>
movl   $0x0,(%r14)
add    $0x1,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1229 <prescan+0xe9>
mov    %rax,%r15
movb   $0x0,(%rax)
cmpl   $0x1,(%r12)
sbb    $0xffffffffffffffff,%r13
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmpl   $0x0,(%r14)
je     1243 <prescan+0x103>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
jmp    1243 <prescan+0x103>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"Uso: %s regexp\0ACon regexp stringa non vuota.\0A\00"
@.str.1 = [52 x i8] c"Errore: Carattere \22backslash\22 alla fine della riga\0A\00"
@.str.2 = [40 x i8] c"Errore prescan: memoria insufficiente.\0A\00"
define i8* @prescan(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i8* null, i8** %10
%12 = load i32*, i32** %9
store i32 0, i32* %12
%13 = load i32*, i32** %8
store i32 0, i32* %13
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %7
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %20)
store i8* null, i8** %5
br label %113
22: ; preds = %4
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 94
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load i32*, i32** %8
store i32 1, i32* %29
br label %30
30: ; preds = %28, %22
%31 = load i8*, i8** %6
%32 = load i32, i32* %11
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 36
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = load i32*, i32** %9
store i32 1, i32* %40
br label %41
41: ; preds = %39, %30
%42 = load i8*, i8** %6
%43 = load i32, i32* %11
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 92
br i1 %49, label %50, label %53
50: ; preds = %41
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %5
br label %113
53: ; preds = %41
%54 = load i32, i32* %11
%55 = icmp sge i32 %54, 2
br i1 %55, label %56, label %67
56: ; preds = %53
%57 = load i8*, i8** %6
%58 = load i32, i32* %11
%59 = sub nsw i32 %58, 2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 92
br i1 %64, label %65, label %67
65: ; preds = %56
%66 = load i32*, i32** %9
store i32 0, i32* %66
br label %67
67: ; preds = %65, %56, %53
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = mul i64 1, %70
%72 = trunc i64 %71 to i32
%73 = call i64 @malloc(i32 %72)
%74 = inttoptr i64 %73 to i8*
store i8* %74, i8** %10
%75 = load i8*, i8** %10
%76 = icmp ne i8* %75, null
br i1 %76, label %80, label %77
77: ; preds = %67
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %5
br label %113
80: ; preds = %67
%81 = load i8*, i8** %10
%82 = getelementptr inbounds i8, i8* %81, i64 0
store i8 0, i8* %82
%83 = load i32*, i32** %8
%84 = load i32, i32* %83
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %93
86: ; preds = %80
%87 = load i8*, i8** %10
%88 = load i8*, i8** %6
%89 = getelementptr inbounds i8, i8* %88, i64 1
%90 = load i32, i32* %11
%91 = add nsw i32 %90, 1
%92 = call i32 @strncpy(i8* %87, i8* %89, i32 %91)
br label %99
93: ; preds = %80
%94 = load i8*, i8** %10
%95 = load i8*, i8** %6
%96 = load i32, i32* %11
%97 = add nsw i32 %96, 1
%98 = call i32 @strncpy(i8* %94, i8* %95, i32 %97)
br label %99
99: ; preds = %93, %86
%100 = load i8*, i8** %10
%101 = call i32 @strlen(i8* %100)
store i32 %101, i32* %11
%102 = load i32*, i32** %9
%103 = load i32, i32* %102
%104 = icmp ne i32 %103, 0
br i1 %104, label %105, label %111
105: ; preds = %99
%106 = load i8*, i8** %10
%107 = load i32, i32* %11
%108 = sub nsw i32 %107, 1
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %106, i64 %109
store i8 0, i8* %110
br label %111
111: ; preds = %105, %99
%112 = load i8*, i8** %10
store i8* %112, i8** %5
br label %113
113: ; preds = %111, %77, %50, %18
%114 = load i8*, i8** %5
ret i8* %114
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"Uso: %s regexp\0ACon regexp stringa non vuota.\0A\00"
@.str.1 = [52 x i8] c"Errore: Carattere \22backslash\22 alla fine della riga\0A\00"
@.str.2 = [40 x i8] c"Errore prescan: memoria insufficiente.\0A\00"
define i8* @prescan(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3) {
store i32 0, i32* %3
store i32 0, i32* %2
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %58
10: ; preds = %4
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 94
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 1, i32* %2
br label %14
14: ; preds = %13, %10
%15 = add nsw i32 %5, -1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 36
br i1 %19, label %20, label %22
20: ; preds = %14
store i32 1, i32* %3
%21 = load i8, i8* %17
br label %22
22: ; preds = %20, %14
%23 = phi i8 [ %21, %20 ], [ %18, %14 ]
%24 = icmp eq i8 %23, 92
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %58
28: ; preds = %22
%29 = icmp ugt i32 %5, 1
br i1 %29, label %30, label %37
30: ; preds = %28
%31 = add nsw i32 %5, -2
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 92
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 0, i32* %3
br label %37
37: ; preds = %36, %30, %28
%38 = add nuw nsw i32 %5, 1
%39 = tail call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
%41 = icmp eq i64 %39, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %58
45: ; preds = %37
store i8 0, i8* %40
%46 = load i32, i32* %2
%47 = icmp ne i32 %46, 0
%48 = zext i1 %47 to i64
%49 = getelementptr i8, i8* %0, i64 %48
%50 = tail call i32 @strncpy(i8* %40, i8* %49, i32 %38)
%51 = tail call i32 @strlen(i8* %40)
%52 = load i32, i32* %3
%53 = icmp eq i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %45
%55 = add nsw i32 %51, -1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %40, i64 %56
store i8 0, i8* %57
br label %58
58: ; preds = %45, %54, %42, %25, %7
%59 = phi i8* [ null, %7 ], [ null, %25 ], [ null, %42 ], [ %40, %54 ], [ %40, %45 ]
ret i8* %59
}