#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*/ printf(char *);
int sha1_check(char *);
int sha1_print(char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int ret, i;
  if (argc == 1) {
    printf("print mode:  sha1sum <file> <file> ...\n");
    printf("check mode:  sha1sum -c <checksum file>\n");
    return (1);
  }
  if (argc == 3 && strcmp("-c", argv[1]) == 0)
    return (sha1_check(argv[2]));
  ret = 0;
  for (i = 1; i < argc; i++)
    ret |= sha1_print(argv[i]);
  return (ret);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1184 <main+0x44>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1206 <main+0xc6>
cmpl   $0x3,-0x8(%rbp)
jne    11c1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xeb4(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <sha1_check@plt>
mov    %eax,-0x4(%rbp)
jmp    1206 <main+0xc6>
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1200 <main+0xc0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <sha1_print@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cf <main+0x8f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
cmp    $0x3,%edi
je     1177 <main+0x37>
cmp    $0x1,%r14d
jne    119f <main+0x5f>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    11d4 <main+0x94>
mov    0x8(%r15),%rsi
lea    0xe7e(%rip),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a7 <main+0x67>
mov    0x10(%r15),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sha1_check@plt>
xor    %ebp,%ebp
cmp    $0x2,%r14d
jl     11d4 <main+0x94>
mov    %r14d,%r14d
xor    %ebp,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
call   1060 <sha1_print@plt>
or     %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11c0 <main+0x80>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"print mode: sha1sum <file> <file> ...\0A\00"
@.str.1 = [41 x i8] c"check mode: sha1sum -c <checksum file>\0A\00"
@.str.2 = [3 x i8] c"-c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %46
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 3
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @sha1_check(i8* %25)
store i32 %26, i32* %3
br label %46
27: ; preds = %16, %13
store i32 0, i32* %6
store i32 1, i32* %7
br label %28
28: ; preds = %41, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %44
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @sha1_print(i8* %37)
%39 = load i32, i32* %6
%40 = or i32 %39, %38
store i32 %40, i32* %6
br label %41
41: ; preds = %32
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %28
44: ; preds = %28
%45 = load i32, i32* %6
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %22, %10
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"-c\00"
@str = [39 x i8] c"print mode: sha1sum <file> <file> ...\00"
@str.3 = [40 x i8] c"check mode: sha1sum -c <checksum file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %15 [
i32 1, label %3
i32 3, label %6
]
3: ; preds = %2
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.3, i64 0, i64 0))
br label %28
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @sha1_check(i8* %13)
br label %28
15: ; preds = %2
%16 = icmp sgt i32 %0, 1
br i1 %16, label %17, label %28
17: ; preds = %6, %15
%18 = zext i32 %0 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 1, %17 ], [ %26, %19 ]
%21 = phi i32 [ 0, %17 ], [ %25, %19 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %20
%23 = load i8*, i8** %22
%24 = tail call i32 @sha1_print(i8* %23)
%25 = or i32 %24, %21
%26 = add nuw nsw i64 %20, 1
%27 = icmp eq i64 %26, %18
br i1 %27, label %28, label %19
28: ; preds = %19, %15, %11, %3
%29 = phi i32 [ 1, %3 ], [ %14, %11 ], [ 0, %15 ], [ %25, %19 ]
ret i32 %29
}