#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*/ buf;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ errx(int, char *);
int getchar();
int hashit(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ octdigit(int);
int /*<<< orphan*/ printf(char *, int);
void copystr(void) {
  int c, ch;
  char buf[512];
  char *cp = buf;
  for (;;) {
    if (cp == buf + sizeof(buf) - 2)
      errx(1, "message too long");
    c = getchar();
    if (c == EOF)
      break;
    switch (c) {
    case '"':
      *cp++ = 0;
      goto out;
    case '\\':
      c = getchar();
      switch (c) {
      case 'b':
        c = '\b';
        break;
      case 't':
        c = '\t';
        break;
      case 'r':
        c = '\r';
        break;
      case 'n':
        c = '\n';
        break;
      case '\n':
        continue;
      case 'f':
        c = '\f';
        break;
      case '0':
        c = 0;
        break;
      case '\\':
        break;
      default:
        if (!octdigit(c))
          break;
        c -= '0';
        ch = getchar();
        if (!octdigit(ch))
          break;
        c <<= 7, c += ch - '0';
        ch = getchar();
        if (!octdigit(ch))
          break;
        c <<= 3, c += ch - '0', ch = -1;
        break;
      }
    }
    *cp++ = c;
  }
out:
  *cp = 0;
  printf("%d", hashit(buf, 1, 0));
}


x86 assembly (clang, -O0):
<copystr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rax
lea    -0x210(%rbp),%rcx
add    $0x200,%rcx
add    $0xfffffffffffffffe,%rcx
cmp    %rcx,%rax
jne    119c <copystr+0x4c>
mov    $0x1,%edi
lea    0xe69(%rip),%rsi
call   1030 <errx@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
jne    11bd <copystr+0x6d>
jmp    13ba <copystr+0x26a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x21c(%rbp)
sub    $0x22,%eax
je     11e8 <copystr+0x98>
jmp    11d4 <copystr+0x84>
mov    -0x21c(%rbp),%eax
sub    $0x5c,%eax
je     1205 <copystr+0xb5>
jmp    1399 <copystr+0x249>
mov    -0x218(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x218(%rbp)
movb   $0x0,(%rax)
jmp    13bf <copystr+0x26f>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x220(%rbp)
sub    $0xa,%eax
je     12e2 <copystr+0x192>
jmp    1226 <copystr+0xd6>
mov    -0x220(%rbp),%eax
sub    $0x30,%eax
je     12f3 <copystr+0x1a3>
jmp    123a <copystr+0xea>
mov    -0x220(%rbp),%eax
sub    $0x5c,%eax
je     12ff <copystr+0x1af>
jmp    124e <copystr+0xfe>
mov    -0x220(%rbp),%eax
sub    $0x62,%eax
je     12b2 <copystr+0x162>
jmp    1262 <copystr+0x112>
mov    -0x220(%rbp),%eax
sub    $0x66,%eax
je     12e7 <copystr+0x197>
jmp    1276 <copystr+0x126>
mov    -0x220(%rbp),%eax
sub    $0x6e,%eax
je     12d6 <copystr+0x186>
jmp    128a <copystr+0x13a>
mov    -0x220(%rbp),%eax
sub    $0x72,%eax
je     12ca <copystr+0x17a>
jmp    129e <copystr+0x14e>
mov    -0x220(%rbp),%eax
sub    $0x74,%eax
je     12be <copystr+0x16e>
jmp    1304 <copystr+0x1b4>
movl   $0x8,-0x4(%rbp)
jmp    1394 <copystr+0x244>
movl   $0x9,-0x4(%rbp)
jmp    1394 <copystr+0x244>
movl   $0xd,-0x4(%rbp)
jmp    1394 <copystr+0x244>
movl   $0xa,-0x4(%rbp)
jmp    1394 <copystr+0x244>
jmp    1169 <copystr+0x19>
movl   $0xc,-0x4(%rbp)
jmp    1394 <copystr+0x244>
movl   $0x0,-0x4(%rbp)
jmp    1394 <copystr+0x244>
jmp    1394 <copystr+0x244>
mov    -0x4(%rbp),%edi
call   1070 <octdigit@plt>
cmp    $0x0,%eax
jne    131a <copystr+0x1ca>
jmp    1394 <copystr+0x244>
mov    -0x4(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <octdigit@plt>
cmp    $0x0,%eax
jne    1343 <copystr+0x1f3>
jmp    1394 <copystr+0x244>
mov    -0x4(%rbp),%eax
shl    $0x7,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <octdigit@plt>
cmp    $0x0,%eax
jne    1378 <copystr+0x228>
jmp    1394 <copystr+0x244>
mov    -0x4(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
jmp    1399 <copystr+0x249>
mov    -0x4(%rbp),%eax
mov    %al,%cl
mov    -0x218(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x218(%rbp)
mov    %cl,(%rax)
jmp    1169 <copystr+0x19>
jmp    13bf <copystr+0x26f>
mov    -0x218(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1060 <hashit@plt>
mov    %eax,%esi
lea    0xc2c(%rip),%rdi
call   1040 <printf@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copystr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsp,%r12
lea    0x1fe(%rsp),%r13
mov    0x2e75(%rip),%rbp
jmp    1188 <copystr+0x38>
mov    $0xc,%r15d
nopl   0x0(%rax,%rax,1)
mov    %r15b,(%r12)
add    $0x1,%r12
cmp    %r13,%r12
jne    119e <copystr+0x4e>
mov    $0x1,%edi
lea    0xf7b(%rip),%rsi
call   1030 <errx@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    0x0(%rbp),%eax
je     127d <copystr+0x12d>
mov    %eax,%r15d
cmp    $0x5c,%eax
jne    11e3 <copystr+0x93>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     1188 <copystr+0x38>
mov    %eax,%ebx
lea    -0x30(%rbx),%r14d
cmp    $0x44,%r14d
ja     1215 <copystr+0xc5>
lea    0xe2b(%rip),%rcx
movslq (%rcx,%r14,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %r15d,%r15d
jmp    1180 <copystr+0x30>
cmp    $0x22,%r15d
je     1274 <copystr+0x124>
jmp    1180 <copystr+0x30>
mov    $0x8,%r15d
jmp    1180 <copystr+0x30>
mov    $0xa,%r15d
jmp    1180 <copystr+0x30>
mov    $0xd,%r15d
jmp    1180 <copystr+0x30>
mov    $0x9,%r15d
jmp    1180 <copystr+0x30>
mov    %ebx,%edi
call   1070 <octdigit@plt>
mov    %ebx,%r15d
test   %eax,%eax
je     1180 <copystr+0x30>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <octdigit@plt>
test   %eax,%eax
je     126c <copystr+0x11c>
shl    $0x7,%r14d
lea    (%r14,%rbx,1),%r15d
add    $0xffffffd0,%r15d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <octdigit@plt>
test   %eax,%eax
je     1180 <copystr+0x30>
lea    (%rbx,%r15,8),%r15d
add    $0xffffffd0,%r15d
jmp    1180 <copystr+0x30>
mov    %r14d,%r15d
jmp    1180 <copystr+0x30>
movb   $0x0,(%r12)
add    $0x1,%r12
movb   $0x0,(%r12)
mov    %rsp,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1060 <hashit@plt>
lea    0xe8d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"message too long\00"
@EOF = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define void @copystr() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8* %5, i8** %4
br label %6
6: ; preds = %69, %32, %0
%7 = load i8*, i8** %4
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds i8, i8* %8, i64 512
%10 = getelementptr inbounds i8, i8* %9, i64 -2
%11 = icmp eq i8* %7, %10
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %6
%15 = call i32 (...) @getchar()
store i32 %15, i32* %1
%16 = load i32, i32* %1
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %14
br label %74
20: ; preds = %14
%21 = load i32, i32* %1
switch i32 %21, label %69 [
i32 34, label %22
i32 92, label %25
]
22: ; preds = %20
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 0, i8* %23
br label %75
25: ; preds = %20
%26 = call i32 (...) @getchar()
store i32 %26, i32* %1
%27 = load i32, i32* %1
switch i32 %27, label %36 [
i32 98, label %28
i32 116, label %29
i32 114, label %30
i32 110, label %31
i32 10, label %32
i32 102, label %33
i32 48, label %34
i32 92, label %35
]
28: ; preds = %25
store i32 8, i32* %1
br label %68
29: ; preds = %25
store i32 9, i32* %1
br label %68
30: ; preds = %25
store i32 13, i32* %1
br label %68
31: ; preds = %25
store i32 10, i32* %1
br label %68
32: ; preds = %25
br label %6
33: ; preds = %25
store i32 12, i32* %1
br label %68
34: ; preds = %25
store i32 0, i32* %1
br label %68
35: ; preds = %25
br label %68
36: ; preds = %25
%37 = load i32, i32* %1
%38 = call i32 @octdigit(i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %36
br label %68
41: ; preds = %36
%42 = load i32, i32* %1
%43 = sub nsw i32 %42, 48
store i32 %43, i32* %1
%44 = call i32 (...) @getchar()
store i32 %44, i32* %2
%45 = load i32, i32* %2
%46 = call i32 @octdigit(i32 %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %41
br label %68
49: ; preds = %41
%50 = load i32, i32* %1
%51 = shl i32 %50, 7
store i32 %51, i32* %1
%52 = load i32, i32* %2
%53 = sub nsw i32 %52, 48
%54 = load i32, i32* %1
%55 = add nsw i32 %54, %53
store i32 %55, i32* %1
%56 = call i32 (...) @getchar()
store i32 %56, i32* %2
%57 = load i32, i32* %2
%58 = call i32 @octdigit(i32 %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %61, label %60
60: ; preds = %49
br label %68
61: ; preds = %49
%62 = load i32, i32* %1
%63 = shl i32 %62, 3
store i32 %63, i32* %1
%64 = load i32, i32* %2
%65 = sub nsw i32 %64, 48
%66 = load i32, i32* %1
%67 = add nsw i32 %66, %65
store i32 %67, i32* %1
store i32 -1, i32* %2
br label %68
68: ; preds = %61, %60, %48, %40, %35, %34, %33, %31, %30, %29, %28
br label %69
69: ; preds = %68, %20
%70 = load i32, i32* %1
%71 = trunc i32 %70 to i8
%72 = load i8*, i8** %4
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %4
store i8 %71, i8* %72
br label %6
74: ; preds = %19
br label %75
75: ; preds = %74, %22
%76 = load i8*, i8** %4
store i8 0, i8* %76
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%78 = call i32 @hashit(i8* %77, i32 1, i32 0)
%79 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %78)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"message too long\00"
@EOF = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define void @copystr() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 510
br label %4
4: ; preds = %44, %0
%5 = phi i8* [ %47, %44 ], [ %2, %0 ]
%6 = icmp eq i8* %5, %3
br label %7
7: ; preds = %4, %17
br i1 %6, label %8, label %10
8: ; preds = %7
%9 = call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %7
%11 = call i32 (...) @getchar()
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %48, label %14
14: ; preds = %10
switch i32 %11, label %39 [
i32 34, label %15
i32 92, label %17
]
15: ; preds = %14
%16 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %5
br label %48
17: ; preds = %14
%18 = call i32 (...) @getchar()
switch i32 %18, label %20 [
i32 98, label %40
i32 116, label %41
i32 114, label %42
i32 110, label %43
i32 10, label %7
i32 102, label %44
i32 48, label %19
i32 92, label %39
]
19: ; preds = %17
br label %44
20: ; preds = %17
%21 = call i32 @octdigit(i32 %18)
%22 = icmp eq i32 %21, 0
br i1 %22, label %44, label %23
23: ; preds = %20
%24 = add nsw i32 %18, -48
%25 = call i32 (...) @getchar()
%26 = call i32 @octdigit(i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %44, label %28
28: ; preds = %23
%29 = shl i32 %24, 7
%30 = add i32 %29, -48
%31 = add i32 %30, %25
%32 = call i32 (...) @getchar()
%33 = call i32 @octdigit(i32 %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %28
%36 = shl i32 %31, 3
%37 = add i32 %36, -48
%38 = add i32 %37, %32
br label %44
39: ; preds = %14, %17
br label %44
40: ; preds = %17
br label %44
41: ; preds = %17
br label %44
42: ; preds = %17
br label %44
43: ; preds = %17
br label %44
44: ; preds = %17, %43, %42, %41, %40, %39, %19, %35, %20, %23, %28
%45 = phi i32 [ %38, %35 ], [ %31, %28 ], [ %24, %23 ], [ %18, %20 ], [ 0, %19 ], [ %11, %39 ], [ 8, %40 ], [ 9, %41 ], [ 13, %42 ], [ 10, %43 ], [ 12, %17 ]
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %46, i8* %5
br label %4
48: ; preds = %10, %15
%49 = phi i8* [ %16, %15 ], [ %5, %10 ]
store i8 0, i8* %49
%50 = call i32 @hashit(i8* %2, i32 1, i32 0)
%51 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %50)
ret void
}