#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 EOF;
int /*<<< orphan*/ errno;
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned long,
                           ...);
int getc(int /*<<< orphan*/);
scalar_t__ hash_file(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int hash_list(void) {
  int rc = 0;
  int ready = 0;
  int c;
  char namebuf[4096];
  size_t n = 0;
  unsigned long lastoff = 0;
  unsigned long off = 0;
  do {
    if ((c = getc(stdin)) == EOF) {
      if (ferror(stdin)) {
        fprintf(stderr,
                "sha1sum"
                ":error reading `%s' at offset %lu: %s\n",
                "[stdin]", off, strerror(errno));
        rc = -1;
        break;
      }
      c = 0;
      ready = 1;
    }
    if (n >= sizeof namebuf) {
      fprintf(stderr,
              "sha1sum"
              ": error reading `%s': "
              "filename at offset %lu too long\n",
              "[stdin]", lastoff);
      rc = -1;
      break;
    }
    namebuf[n++] = c;
    off++;
    if (!c) {
      if (*namebuf && hash_file(namebuf, NULL))
        rc = -1;
      n = 0;
      lastoff = off;
    }
  } while (!ready);
  return rc;
}


x86 assembly (clang, -O0):
<hash_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x1018(%rbp)
movq   $0x0,-0x1020(%rbp)
movq   $0x0,-0x1028(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1070 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
jne    122c <hash_list+0xdc>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     121e <hash_list+0xce>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x1028(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1034(%rbp),%edi
mov    -0x1030(%rbp),%rcx
mov    %eax,%r8d
lea    0xdfc(%rip),%rsi
lea    0xe23(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130b <hash_list+0x1bb>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
cmpq   $0x1000,-0x1018(%rbp)
jb     126e <hash_list+0x11e>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x1020(%rbp),%rcx
lea    0xde2(%rip),%rsi
lea    0xdd3(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130b <hash_list+0x1bb>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x1018(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1018(%rbp)
mov    %cl,-0x1010(%rbp,%rax,1)
mov    -0x1028(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1028(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12f5 <hash_list+0x1a5>
movsbl -0x1010(%rbp),%eax
cmp    $0x0,%eax
je     12dc <hash_list+0x18c>
lea    -0x1010(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <hash_file@plt>
cmp    $0x0,%rax
je     12dc <hash_list+0x18c>
movl   $0xffffffff,-0x4(%rbp)
movq   $0x0,-0x1018(%rbp)
mov    -0x1028(%rbp),%rax
mov    %rax,-0x1020(%rbp)
jmp    12fa <hash_list+0x1aa>
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118a <hash_list+0x3a>
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
xor    %r14d,%r14d
mov    0x2e7d(%rip),%rbp
xor    %r15d,%r15d
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    118f <hash_list+0x3f>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r15d,%r15d
mov    %rbx,%r12
test   %r13d,%r13d
jne    127e <hash_list+0x12e>
mov    0x0(%rbp),%edi
call   1070 <getc@plt>
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
jne    11d0 <hash_list+0x80>
mov    0x0(%rbp),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1244 <hash_list+0xf4>
cmp    $0xfff,%r15
ja     1221 <hash_list+0xd1>
movb   $0x0,(%rsp,%r15,1)
add    $0x1,%rbx
mov    $0x1,%r13d
jmp    1200 <hash_list+0xb0>
nopl   (%rax)
cmp    $0xfff,%r15
ja     1221 <hash_list+0xd1>
mov    %al,(%rsp,%r15,1)
add    $0x1,%rbx
xor    %r13d,%r13d
test   %eax,%eax
je     1200 <hash_list+0xb0>
add    $0x1,%r15
test   %r13d,%r13d
je     118f <hash_list+0x3f>
jmp    127e <hash_list+0x12e>
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x0,(%rsp)
je     1180 <hash_list+0x30>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <hash_file@plt>
neg    %rax
sbb    %eax,%eax
or     %eax,%r14d
jmp    1180 <hash_list+0x30>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
lea    0xdf6(%rip),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1278 <hash_list+0x128>
mov    0x2d85(%rip),%rax
mov    (%rax),%ebp
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xd9e(%rip),%rsi
lea    0xdc5(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"sha1sum:error reading `%s' at offset %lu: %s\0A\00"
@.str.1 = [8 x i8] c"[stdin]\00"
@errno = global i32 0
@.str.2 = [62 x i8] c"sha1sum: error reading `%s': filename at offset %lu too long\0A\00"
define i32 @hash_list() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
store i64 0, i64* %5
store i64 0, i64* %6
store i64 0, i64* %7
br label %8
8: ; preds = %54, %0
%9 = load i32, i32* @stdin
%10 = call i32 @getc(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = load i32, i32* @stdin
%15 = call i64 @ferror(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i64, i64* %7
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %19, i32 %21)
store i32 -1, i32* %1
br label %58
23: ; preds = %13
store i32 0, i32* %3
store i32 1, i32* %2
br label %24
24: ; preds = %23, %8
%25 = load i64, i64* %5
%26 = icmp uge i64 %25, 4096
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = load i64, i64* %6
%30 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %29)
store i32 -1, i32* %1
br label %58
31: ; preds = %24
%32 = load i32, i32* %3
%33 = trunc i32 %32 to i8
%34 = load i64, i64* %5
%35 = add i64 %34, 1
store i64 %35, i64* %5
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %34
store i8 %33, i8* %36
%37 = load i64, i64* %7
%38 = add i64 %37, 1
store i64 %38, i64* %7
%39 = load i32, i32* %3
%40 = icmp ne i32 %39, 0
br i1 %40, label %53, label %41
41: ; preds = %31
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%48 = call i64 @hash_file(i8* %47, i32* null)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 -1, i32* %1
br label %51
51: ; preds = %50, %46, %41
store i64 0, i64* %5
%52 = load i64, i64* %7
store i64 %52, i64* %6
br label %53
53: ; preds = %51, %31
br label %54
54: ; preds = %53
%55 = load i32, i32* %2
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
br i1 %57, label %8, label %58
58: ; preds = %54, %27, %17
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"sha1sum:error reading `%s' at offset %lu: %s\0A\00"
@.str.1 = [8 x i8] c"[stdin]\00"
@errno = global i32 0
@.str.2 = [62 x i8] c"sha1sum: error reading `%s': filename at offset %lu too long\0A\00"
define i32 @hash_list() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %46, %0
%4 = phi i32 [ 0, %0 ], [ %49, %46 ]
%5 = phi i64 [ 0, %0 ], [ %50, %46 ]
%6 = phi i64 [ 0, %0 ], [ %51, %46 ]
%7 = phi i64 [ 0, %0 ], [ %47, %46 ]
%8 = load i32, i32* @stdin
%9 = call i32 @getc(i32 %8)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i32, i32* @stdin
%14 = call i64 @ferror(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %7, i32 %19)
br label %53
21: ; preds = %3
%22 = icmp ugt i64 %5, 4095
br i1 %22, label %28, label %31
23: ; preds = %12
%24 = icmp ugt i64 %5, 4095
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %5
store i8 0, i8* %26
%27 = add i64 %7, 1
br label %37
28: ; preds = %23, %21
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %6)
br label %53
31: ; preds = %21
%32 = trunc i32 %9 to i8
%33 = add nuw nsw i64 %5, 1
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %5
store i8 %32, i8* %34
%35 = add i64 %7, 1
%36 = icmp eq i32 %9, 0
br i1 %36, label %37, label %46
37: ; preds = %25, %31
%38 = phi i64 [ %27, %25 ], [ %35, %31 ]
%39 = phi i32 [ 1, %25 ], [ 0, %31 ]
%40 = load i8, i8* %2
%41 = icmp eq i8 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %37
%43 = call i64 @hash_file(i8* %2, i32* null)
%44 = icmp eq i64 %43, 0
%45 = select i1 %44, i32 %4, i32 -1
br label %46
46: ; preds = %42, %37, %31
%47 = phi i64 [ %35, %31 ], [ %38, %37 ], [ %38, %42 ]
%48 = phi i32 [ 0, %31 ], [ %39, %37 ], [ %39, %42 ]
%49 = phi i32 [ %4, %31 ], [ %4, %37 ], [ %45, %42 ]
%50 = phi i64 [ %33, %31 ], [ 0, %37 ], [ 0, %42 ]
%51 = phi i64 [ %6, %31 ], [ %38, %37 ], [ %38, %42 ]
%52 = icmp eq i32 %48, 0
br i1 %52, label %3, label %53
53: ; preds = %46, %28, %16
%54 = phi i32 [ -1, %16 ], [ -1, %28 ], [ %49, %46 ]
ret i32 %54
}