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

/* Variables and functions */
int chksum(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int, int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char **argv) {
  int sum;
  int blocks;
  FILE *fp;
  if (argc == 1) {
    sum = chksum(stdin, &blocks);
    printf("%05d %5d\n", sum, blocks);
  } else {
    int i;
    for (i = 1; i < argc; i++) {
      fp = fopen(argv[i], "r");
      if (fp == NULL) {
        fprintf(stderr, "%s: fopen failed\n", argv[i]);
      } else {
        sum = chksum(fp, &blocks);
        printf("%05d %5d %s\n", sum, blocks, argv[i]);
        fclose(fp);
      }
    }
  }
  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)
cmpl   $0x1,-0x8(%rbp)
jne    119f <main+0x4f>
mov    0x2e71(%rip),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <chksum@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1250 <main+0x100>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    124b <main+0xfb>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe45(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ff <main+0xaf>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe17(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1238 <main+0xe8>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <chksum@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    123d <main+0xed>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <main+0x56>
jmp    1250 <main+0x100>
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
push   %rax
cmp    $0x1,%edi
jne    118d <main+0x3d>
mov    0x2e81(%rip),%rax
mov    (%rax),%rdi
lea    0x4(%rsp),%rsi
call   1030 <chksum@plt>
mov    0x4(%rsp),%edx
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1211 <main+0xc1>
jle    1211 <main+0xc1>
mov    %rsi,%rbx
mov    %edi,%r15d
mov    $0x1,%r12d
lea    0xe64(%rip),%r14
lea    0xe71(%rip),%r13
jmp    11e5 <main+0x95>
nop
mov    %rax,%rbp
mov    %rax,%rdi
lea    0x4(%rsp),%rsi
call   1030 <chksum@plt>
mov    0x4(%rsp),%edx
mov    (%rbx,%r12,8),%rcx
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
add    $0x1,%r12
cmp    %r12,%r15
je     1211 <main+0xc1>
mov    (%rbx,%r12,8),%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11b0 <main+0x60>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%r12,8),%rdx
lea    0xe02(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11dc <main+0x8c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [10 x i8] c"%05d %5d\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"%s: fopen failed\0A\00"
@.str.3 = [13 x i8] c"%05d %5d %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32*, i32** @stdin
%14 = call i32 @chksum(i32* %13, i32* %7)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
br label %58
18: ; preds = %2
store i32 1, i32* %9
br label %19
19: ; preds = %54, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %57
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %40
32: ; preds = %23
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %53
40: ; preds = %23
%41 = load i32*, i32** %8
%42 = call i32 @chksum(i32* %41, i32* %7)
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = load i8**, i8*** %5
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %44, i8* %49)
%51 = load i32*, i32** %8
%52 = call i32 @fclose(i32* %51)
br label %53
53: ; preds = %40, %32
br label %54
54: ; preds = %53
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %19
57: ; preds = %19
br label %58
58: ; preds = %57, %12
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [10 x i8] c"%05d %5d\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"%s: fopen failed\0A\00"
@.str.3 = [13 x i8] c"%05d %5d %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %34
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %15
10: ; preds = %2
%11 = load i32*, i32** @stdin
%12 = call i32 @chksum(i32* %11, i32* %3)
%13 = load i32, i32* %3
%14 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
br label %34
15: ; preds = %8, %31
%16 = phi i64 [ 1, %8 ], [ %32, %31 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %17
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %31
25: ; preds = %15
%26 = call i32 @chksum(i32* %19, i32* %3)
%27 = load i32, i32* %3
%28 = load i8*, i8** %17
%29 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27, i8* %28)
%30 = call i32 @fclose(i32* %19)
br label %31
31: ; preds = %21, %25
%32 = add nuw nsw i64 %16, 1
%33 = icmp eq i64 %32, %9
br i1 %33, label %34, label %15
34: ; preds = %31, %6, %10
ret i32 0
}