#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*/ fgets(char *, int, int /*<<< orphan*/);
int longhash(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char *str = malloc(200 * sizeof(char));
  int i;
  printf("Enter a string: ");
  fgets(str, 200, stdin);
  while (strlen(str) >= 200) {
    printf("Enter a string: ");
    fgets(str, 200, stdin);
  }
  i = strlen(str) - 1;
  if (str[i] == '\n')
    str[i] = '\0';
  printf("hash = %d", longhash(str));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    $0xc8,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xc8,%eax
jl     11d0 <main+0x80>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
mov    $0xc8,%esi
call   1060 <fgets@plt>
jmp    1192 <main+0x42>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1200 <main+0xb0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <longhash@plt>
mov    %eax,%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e71(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0xc8,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0xc8,%eax
jl     11c9 <main+0x79>
lea    0xe63(%rip),%r14
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0xc8,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0xc7,%eax
jg     11a0 <main+0x50>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11df <main+0x8f>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <longhash@plt>
lea    0xe23(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a string: \00"
@stdin = global i32 0
@.str.1 = [10 x i8] c"hash = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i8* @malloc(i32 200)
store i8* %4, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 200, i32 %7)
br label %9
9: ; preds = %13, %0
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = icmp sge i32 %11, 200
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %2
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 200, i32 %16)
br label %9
18: ; preds = %9
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %3
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %34
29: ; preds = %18
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %29, %18
%35 = load i8*, i8** %2
%36 = call i32 @longhash(i8* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a string: \00"
@stdin = global i32 0
@.str.1 = [10 x i8] c"hash = %d\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %1, i32 200, i32 %3)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 199
br i1 %6, label %7, label %13
7: ; preds = %0, %7
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = tail call i32 @fgets(i8* %1, i32 200, i32 %9)
%11 = tail call i32 @strlen(i8* %1)
%12 = icmp sgt i32 %11, 199
br i1 %12, label %7, label %13
13: ; preds = %7, %0
%14 = tail call i32 @strlen(i8* %1)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %21
20: ; preds = %13
store i8 0, i8* %17
br label %21
21: ; preds = %20, %13
%22 = tail call i32 @longhash(i8* %1)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %22)
ret i32 0
}