#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *malloc(size_t);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
char *escapefname(const char *fname, int *escaped) {
  const char *s;
  char *buffer;
  char *d;
  size_t n;
  *escaped = 0;
  for (n = 0, s = fname; *s; s++) {
    if (*s == '\n' || *s == '\r')
      n += 2;
    else if (*s == '\\') {
      n += 2;
    } else
      n++;
  }
  n++;
  buffer = malloc(n);
  if (!buffer) {
    fprintf(stderr,
            "sha1sum"
            ": can't allocate buffer: %s\n",
            strerror(errno));
    exit(2);
  }
  d = buffer;
  for (s = fname; *s; s++) {
    if (*s == '\n') {
      *d++ = '\\';
      *d++ = 'n';
      *escaped = 1;
    } else if (*s == '\r') {
      *d++ = '\\';
      *d++ = 'r';
      *escaped = 1;
    } else if (*s == '\\') {
      *d++ = '\\';
      *d++ = '\\';
      *escaped = 1;
    } else
      *d++ = *s;
  }
  *d = 0;
  return buffer;
}


x86 assembly (clang, -O0):
<escapefname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f0 <escapefname+0xb0>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1197 <escapefname+0x57>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11a8 <escapefname+0x68>
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
jmp    11da <escapefname+0x9a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11c9 <escapefname+0x89>
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
jmp    11d5 <escapefname+0x95>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11da <escapefname+0x9a>
jmp    11df <escapefname+0x9f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116a <escapefname+0x2a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    124a <escapefname+0x10a>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xdc5(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1367 <escapefname+0x227>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    12aa <escapefname+0x16a>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x5c,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x6e,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    1351 <escapefname+0x211>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    12ed <escapefname+0x1ad>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x5c,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x72,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    134c <escapefname+0x20c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1330 <escapefname+0x1f0>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x5c,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    1347 <escapefname+0x207>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    134c <escapefname+0x20c>
jmp    1351 <escapefname+0x211>
jmp    1356 <escapefname+0x216>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    125a <escapefname+0x11a>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escapefname>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rsi)
xor    %edi,%edi
mov    %rbx,%rax
jmp    116c <escapefname+0x2c>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%ecx
add    %rcx,%rdi
add    $0x1,%rax
movzbl (%rax),%edx
mov    $0x2,%ecx
cmp    $0xc,%dl
jle    1190 <escapefname+0x50>
cmp    $0xd,%dl
je     1165 <escapefname+0x25>
cmp    $0x5c,%dl
je     1165 <escapefname+0x25>
jmp    1160 <escapefname+0x20>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xa,%dl
je     1165 <escapefname+0x25>
test   %dl,%dl
jne    1160 <escapefname+0x20>
add    $0x1,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1207 <escapefname+0xc7>
mov    %rax,%rcx
jmp    11c4 <escapefname+0x84>
nopl   0x0(%rax)
movw   $0x725c,(%rcx)
add    $0x2,%rcx
movl   $0x1,(%r14)
add    $0x1,%rbx
movzbl (%rbx),%edx
cmp    $0xc,%dl
jle    11e0 <escapefname+0xa0>
cmp    $0xd,%dl
je     11b0 <escapefname+0x70>
cmp    $0x5c,%dl
jne    11f0 <escapefname+0xb0>
movw   $0x5c5c,(%rcx)
jmp    11b5 <escapefname+0x75>
nopl   (%rax)
cmp    $0xa,%dl
jne    11ec <escapefname+0xac>
movw   $0x6e5c,(%rcx)
jmp    11b5 <escapefname+0x75>
test   %dl,%dl
je     11fc <escapefname+0xbc>
mov    %dl,(%rcx)
add    $0x1,%rcx
add    $0x1,%rbx
jmp    11c4 <escapefname+0x84>
movb   $0x0,(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd2(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xddb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"sha1sum: can't allocate buffer: %s\0A\00"
@errno = global i32 0
define noalias i8* @escapefname(i8* nocapture %0, i32* nocapture writeonly %1) {
store i32 0, i32* %1
br label %3
3: ; preds = %8, %2
%4 = phi i8* [ %0, %2 ], [ %11, %8 ]
%5 = phi i64 [ 0, %2 ], [ %10, %8 ]
%6 = load i8, i8* %4
switch i8 %6, label %7 [
i8 0, label %12
i8 10, label %8
i8 13, label %8
i8 92, label %8
]
7: ; preds = %3
br label %8
8: ; preds = %3, %3, %3, %7
%9 = phi i64 [ 1, %7 ], [ 2, %3 ], [ 2, %3 ], [ 2, %3 ]
%10 = add i64 %5, %9
%11 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
12: ; preds = %3
%13 = add i64 %5, 1
%14 = tail call i8* @malloc(i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 2)
unreachable
22: ; preds = %12, %37
%23 = phi i8* [ %39, %37 ], [ %0, %12 ]
%24 = phi i8* [ %38, %37 ], [ %14, %12 ]
%25 = load i8, i8* %23
switch i8 %25, label %35 [
i8 0, label %40
i8 10, label %26
i8 13, label %29
i8 92, label %32
]
26: ; preds = %22
%27 = getelementptr inbounds i8, i8* %24, i64 1
store i8 92, i8* %24
%28 = getelementptr inbounds i8, i8* %24, i64 2
store i8 110, i8* %27
store i32 1, i32* %1
br label %37
29: ; preds = %22
%30 = getelementptr inbounds i8, i8* %24, i64 1
store i8 92, i8* %24
%31 = getelementptr inbounds i8, i8* %24, i64 2
store i8 114, i8* %30
store i32 1, i32* %1
br label %37
32: ; preds = %22
%33 = getelementptr inbounds i8, i8* %24, i64 1
store i8 92, i8* %24
%34 = getelementptr inbounds i8, i8* %24, i64 2
store i8 92, i8* %33
store i32 1, i32* %1
br label %37
35: ; preds = %22
%36 = getelementptr inbounds i8, i8* %24, i64 1
store i8 %25, i8* %24
br label %37
37: ; preds = %26, %32, %35, %29
%38 = phi i8* [ %28, %26 ], [ %31, %29 ], [ %34, %32 ], [ %36, %35 ]
%39 = getelementptr inbounds i8, i8* %23, i64 1
br label %22
40: ; preds = %22
store i8 0, i8* %24
ret i8* %14
}