#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 _cksum_do(int /*<<< orphan*/ *, char *);
int _cksum_error(char *, int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *stdin;
int _cksum(int argc, char *argv[]) {
  int i;
  int ret = 0;
  FILE *fp;
  if (argc == 0)
    return _cksum_do(stdin, "stdin") == 0 ? 0 : 2;
  for (i = 0; i < argc; i++) {
    if ((fp = fopen(argv[i], "r")) == NULL) {
      ret |= _cksum_error(argv[i], 1);
      continue;
    }
    ret |= _cksum_do(fp, argv[i]);
    if (fclose(fp) != 0)
      ret |= _cksum_error(argv[i], 1);
  }
  return ret;
}


x86 assembly (clang, -O0):
<_cksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    118d <_cksum+0x4d>
mov    0x2e81(%rip),%rax
mov    (%rax),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <_cksum_do@plt>
mov    %eax,%edx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    124a <_cksum+0x10a>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1244 <_cksum+0x104>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe53(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e7 <_cksum+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x1,%esi
call   1030 <_cksum_error@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1236 <_cksum+0xf6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <_cksum_do@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1231 <_cksum+0xf1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x1,%esi
call   1030 <_cksum_error@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1236 <_cksum+0xf6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <_cksum+0x54>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cksum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
je     11cc <_cksum+0x8c>
jle    11f0 <_cksum+0xb0>
mov    %rsi,%r15
mov    %edi,%r12d
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    118f <_cksum+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%r14d
mov    %rsi,%rdi
mov    $0x1,%esi
call   1030 <_cksum_error@plt>
or     %eax,%r14d
add    $0x1,%rbp
mov    %r14d,%r13d
cmp    %rbp,%r12
je     11f3 <_cksum+0xb3>
mov    (%r15,%rbp,8),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    (%r15,%rbp,8),%rsi
test   %rax,%rax
je     1170 <_cksum+0x30>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <_cksum_do@plt>
mov    %eax,%r14d
or     %r13d,%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1183 <_cksum+0x43>
mov    (%r15,%rbp,8),%rsi
jmp    1173 <_cksum+0x33>
mov    0x2e15(%rip),%rax
mov    (%rax),%rdi
lea    0xe23(%rip),%rsi
call   1050 <_cksum_do@plt>
xor    %r14d,%r14d
test   %eax,%eax
setne  %r14b
add    %r14d,%r14d
jmp    11f3 <_cksum+0xb3>
xor    %r14d,%r14d
mov    %r14d,%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 = [6 x i8] c"stdin\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @_cksum(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32*, i32** @stdin
%13 = call i32 @_cksum_do(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 0, i32 2
store i32 %16, i32* %3
br label %67
17: ; preds = %2
store i32 0, i32* %6
br label %18
18: ; preds = %62, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %65
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %8
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %39
30: ; preds = %22
%31 = load i8**, i8*** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @_cksum_error(i8* %35, i32 1)
%37 = load i32, i32* %7
%38 = or i32 %37, %36
store i32 %38, i32* %7
br label %62
39: ; preds = %22
%40 = load i32*, i32** %8
%41 = load i8**, i8*** %5
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @_cksum_do(i32* %40, i8* %45)
%47 = load i32, i32* %7
%48 = or i32 %47, %46
store i32 %48, i32* %7
%49 = load i32*, i32** %8
%50 = call i64 @fclose(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %39
%53 = load i8**, i8*** %5
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @_cksum_error(i8* %57, i32 1)
%59 = load i32, i32* %7
%60 = or i32 %59, %58
store i32 %60, i32* %7
br label %61
61: ; preds = %52, %39
br label %62
62: ; preds = %61, %30
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %18
65: ; preds = %18
%66 = load i32, i32* %7
store i32 %66, i32* %3
br label %67
67: ; preds = %65, %11
%68 = load i32, i32* %3
ret i32 %68
}

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