#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
char *magma_armour_hash(unsigned char *);
unsigned char *magma_sha1_data(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
unsigned char *sha1_fd(int);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  unsigned char *hash;
  struct stat buf;
  int c, fd;
  for (c = 1; c < argc; c++) {
    if (!stat(argv[c], &buf)) {
      if ((fd = open(argv[c], 0)) > 1) {
        hash = sha1_fd(fd);
        close(fd);
      } else {
        printf("Can't open file %s\n", argv[c]);
        continue;
      }
    } else {
      hash = magma_sha1_data(argv[c], strlen(argv[c]));
    }
    printf("%s  %s\n", magma_armour_hash(hash), argv[c]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1287 <main+0x107>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%eax
jne    1223 <main+0xa3>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %esi,%esi
call   1090 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x1,%eax
jle    11ff <main+0x7f>
mov    -0x28(%rbp),%edi
call   1060 <sha1_fd@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
jmp    121e <main+0x9e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1279 <main+0xf9>
jmp    1253 <main+0xd3>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1080 <magma_sha1_data@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <magma_armour_hash@plt>
mov    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     125a <main+0xda>
mov    %rsi,%r13
mov    %edi,%r15d
mov    $0x1,%r12d
lea    0x10(%rsp),%rbp
lea    0xe65(%rip),%r14
mov    %r15,0x8(%rsp)
jmp    11f8 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <magma_sha1_data@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   10a0 <magma_armour_hash@plt>
mov    0x0(%r13,%r12,8),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
cmp    %r12,%r15
je     125a <main+0xda>
mov    0x0(%r13,%r12,8),%rdi
mov    %rbp,%rsi
call   1070 <stat@plt>
mov    0x0(%r13,%r12,8),%rbx
test   %eax,%eax
jne    11c0 <main+0x40>
mov    %rbp,%r15
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <open@plt>
cmp    $0x2,%eax
jl     123d <main+0xbd>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <sha1_fd@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r15,%rbp
mov    0x8(%rsp),%r15
jmp    11d5 <main+0x55>
mov    0x0(%r13,%r12,8),%rsi
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rbp
mov    0x8(%rsp),%r15
jmp    11ef <main+0x6f>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [20 x i8] c"Can't open file %s\0A\00"
@.str.1 = [8 x i8] c"%s %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.stat
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
br label %10
10: ; preds = %65, %2
%11 = load i32, i32* %8
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %68
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @stat(i8* %19, %struct.stat* %7)
%21 = icmp ne i32 %20, 0
br i1 %21, label %43, label %22
22: ; preds = %14
%23 = load i8**, i8*** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @open(i8* %27, i32 0)
store i32 %28, i32* %9
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load i32, i32* %9
%32 = call i8* @sha1_fd(i32 %31)
store i8* %32, i8** %6
%33 = load i32, i32* %9
%34 = call i32 @close(i32 %33)
br label %42
35: ; preds = %22
%36 = load i8**, i8*** %5
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %40)
br label %65
42: ; preds = %30
br label %56
43: ; preds = %14
%44 = load i8**, i8*** %5
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %5
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @strlen(i8* %53)
%55 = call i8* @magma_sha1_data(i8* %48, i32 %54)
store i8* %55, i8** %6
br label %56
56: ; preds = %43, %42
%57 = load i8*, i8** %6
%58 = call i8* @magma_armour_hash(i8* %57)
%59 = load i8**, i8*** %5
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %58, i8* %63)
br label %65
65: ; preds = %56, %35
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %10
68: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [20 x i8] c"Can't open file %s\0A\00"
@.str.1 = [8 x i8] c"%s %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %35
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %32
%9 = phi i64 [ 1, %6 ], [ %33, %32 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = call i32 @stat(i8* %11, %struct.stat* %3)
%13 = icmp eq i32 %12, 0
%14 = load i8*, i8** %10
br i1 %13, label %15, label %24
15: ; preds = %8
%16 = tail call i32 @open(i8* %14, i32 0)
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i8* @sha1_fd(i32 %16)
%20 = tail call i32 @close(i32 %16)
br label %27
21: ; preds = %15
%22 = load i8*, i8** %10
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %32
24: ; preds = %8
%25 = tail call i32 @strlen(i8* %14)
%26 = tail call i8* @magma_sha1_data(i8* %14, i32 %25)
br label %27
27: ; preds = %24, %18
%28 = phi i8* [ %26, %24 ], [ %19, %18 ]
%29 = tail call i8* @magma_armour_hash(i8* %28)
%30 = load i8*, i8** %10
%31 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30)
br label %32
32: ; preds = %27, %21
%33 = add nuw nsw i64 %9, 1
%34 = icmp eq i64 %33, %7
br i1 %34, label %35, label %8
35: ; preds = %32, %2
ret i32 0
}