#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 uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ adler32(unsigned char *, long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  long bufsize;
  if (argc != 2) {
    fputs("Need 1 argument\n", stderr);
    return (EXIT_FAILURE);
  }
  unsigned char *source = NULL;
  FILE *fp = fopen(argv[1], "rb");
  if (fp != NULL) {
    if (fseek(fp, 0L, SEEK_END) == 0) {
      bufsize = ftell(fp);
      if (bufsize == -1) {
        fputs("Couldn't get size\n", stderr);
        return (EXIT_FAILURE);
      }
      source = malloc(sizeof(char) * (bufsize + 1));
      if (source == NULL) {
        fputs("Couldn't allocate\n", stderr);
        return (EXIT_FAILURE);
      }
      if (fseek(fp, 0L, SEEK_SET) == -1) {
        fputs("Couldn't seek\n", stderr);
        return (EXIT_FAILURE);
      }
      size_t newLen = fread(source, sizeof(char), bufsize, fp);
      if (newLen == 0) {
        fputs("Error reading file\n", stderr);
      } else {
        source[++newLen] = '\0';
      }
    } else {
      fputs("Couldn't seek to end\n", stderr);
      return (EXIT_FAILURE);
    }
    fclose(fp);
  } else {
    fputs("Couldn't open\n", stderr);
    return (EXIT_FAILURE);
  }
  printf("%d\n", (uint32_t)adler32(source, bufsize));
  free(source);
  return (EXIT_SUCCESS);
}


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   $0x2,-0x8(%rbp)
je     11e6 <main+0x46>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e1 <main+0x241>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe14(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     138b <main+0x1eb>
mov    -0x28(%rbp),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
cmp    $0x0,%eax
jne    1357 <main+0x1b7>
mov    -0x28(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    126e <main+0xce>
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
lea    0xdbc(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e1 <main+0x241>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12b6 <main+0x116>
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
lea    0xd87(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e1 <main+0x241>
mov    -0x28(%rbp),%rdi
mov    0x2d0f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
cmp    $0xffffffff,%eax
jne    12fb <main+0x15b>
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
lea    0xd55(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e1 <main+0x241>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    133a <main+0x19a>
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
lea    0xd19(%rip),%rdi
call   1070 <fputs@plt>
jmp    1352 <main+0x1b2>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
movb   $0x0,0x1(%rax,%rcx,1)
jmp    137d <main+0x1dd>
mov    0x2c7a(%rip),%rax
mov    (%rax),%esi
lea    0xcf6(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e1 <main+0x241>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
jmp    13b1 <main+0x211>
mov    0x2c46(%rip),%rax
mov    (%rax),%esi
lea    0xcd8(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2c21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e1 <main+0x241>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <adler32@plt>
mov    %eax,%esi
lea    0xcbb(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2be4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11eb <main+0x4b>
mov    0x8(%rsi),%rdi
lea    0xe5c(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     11fd <main+0x5d>
mov    %rax,%rbx
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
test   %eax,%eax
je     1221 <main+0x81>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
jmp    120d <main+0x6d>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe05(%rip),%rdi
jmp    120d <main+0x6d>
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
lea    0xe66(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1080 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     127a <main+0xda>
mov    %rax,%r14
lea    0x1(%rax),%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     128c <main+0xec>
mov    %rax,%r15
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
cmp    $0xffffffff,%eax
je     12a1 <main+0x101>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     12b6 <main+0x116>
movb   $0x0,0x1(%rax,%r15,1)
jmp    12cb <main+0x12b>
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    0xd8a(%rip),%rdi
jmp    120d <main+0x6d>
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
lea    0xd8b(%rip),%rdi
jmp    120d <main+0x6d>
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    0xd89(%rip),%rdi
jmp    120d <main+0x6d>
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
lea    0xd83(%rip),%rdi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <adler32@plt>
lea    0xd9d(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2cc5(%rip),%rax
jmp    1219 <main+0x79>

LLVM IR (-O0):
@.str = [17 x i8] c"Need 1 argument\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [19 x i8] c"Couldn't get size\0A\00"
@.str.3 = [19 x i8] c"Couldn't allocate\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [15 x i8] c"Couldn't seek\0A\00"
@.str.5 = [20 x i8] c"Error reading file\0A\00"
@.str.6 = [22 x i8] c"Couldn't seek to end\0A\00"
@.str.7 = [15 x i8] c"Couldn't open\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %94
16: ; preds = %2
store i8* null, i8** %7
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %8
%21 = load i32*, i32** %8
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %81
23: ; preds = %16
%24 = load i32*, i32** %8
%25 = load i32, i32* @SEEK_END
%26 = call i32 @fseek(i32* %24, i64 0, i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %74
28: ; preds = %23
%29 = load i32*, i32** %8
%30 = call i64 @ftell(i32* %29)
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = icmp eq i64 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @EXIT_FAILURE
store i32 %36, i32* %3
br label %94
37: ; preds = %28
%38 = load i64, i64* %6
%39 = add nsw i64 %38, 1
%40 = mul i64 1, %39
%41 = trunc i64 %40 to i32
%42 = call i8* @malloc(i32 %41)
store i8* %42, i8** %7
%43 = load i8*, i8** %7
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %94
49: ; preds = %37
%50 = load i32*, i32** %8
%51 = load i32, i32* @SEEK_SET
%52 = call i32 @fseek(i32* %50, i64 0, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %55)
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %3
br label %94
58: ; preds = %49
%59 = load i8*, i8** %7
%60 = load i64, i64* %6
%61 = load i32*, i32** %8
%62 = call i64 @fread(i8* %59, i32 1, i64 %60, i32* %61)
store i64 %62, i64* %9
%63 = load i64, i64* %9
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %58
%66 = load i32, i32* @stderr
%67 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %66)
br label %73
68: ; preds = %58
%69 = load i8*, i8** %7
%70 = load i64, i64* %9
%71 = add i64 %70, 1
store i64 %71, i64* %9
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 0, i8* %72
br label %73
73: ; preds = %68, %65
br label %78
74: ; preds = %23
%75 = load i32, i32* @stderr
%76 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %75)
%77 = load i32, i32* @EXIT_FAILURE
store i32 %77, i32* %3
br label %94
78: ; preds = %73
%79 = load i32*, i32** %8
%80 = call i32 @fclose(i32* %79)
br label %85
81: ; preds = %16
%82 = load i32, i32* @stderr
%83 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %82)
%84 = load i32, i32* @EXIT_FAILURE
store i32 %84, i32* %3
br label %94
85: ; preds = %78
%86 = load i8*, i8** %7
%87 = load i64, i64* %6
%88 = call i64 @adler32(i8* %86, i64 %87)
%89 = trunc i64 %88 to i32
%90 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %89)
%91 = load i8*, i8** %7
%92 = call i32 @free(i8* %91)
%93 = load i32, i32* @EXIT_SUCCESS
store i32 %93, i32* %3
br label %94
94: ; preds = %85, %81, %74, %54, %45, %33, %12
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [17 x i8] c"Need 1 argument\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [19 x i8] c"Couldn't get size\0A\00"
@.str.3 = [19 x i8] c"Couldn't allocate\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [15 x i8] c"Couldn't seek\0A\00"
@.str.5 = [20 x i8] c"Error reading file\0A\00"
@.str.6 = [22 x i8] c"Couldn't seek to end\0A\00"
@.str.7 = [15 x i8] c"Couldn't open\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %58
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %55, label %12
12: ; preds = %7
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @fseek(i32* %10, i64 0, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %52
16: ; preds = %12
%17 = tail call i64 @ftell(i32* %10)
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %58
22: ; preds = %16
%23 = trunc i64 %17 to i32
%24 = add i32 %23, 1
%25 = tail call i8* @malloc(i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %58
30: ; preds = %22
%31 = load i32, i32* @SEEK_SET
%32 = tail call i32 @fseek(i32* %10, i64 0, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = tail call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %58
37: ; preds = %30
%38 = tail call i64 @fread(i8* %25, i32 1, i64 %17, i32* %10)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = tail call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %41)
br label %46
43: ; preds = %37
%44 = add i64 %38, 1
%45 = getelementptr inbounds i8, i8* %25, i64 %44
store i8 0, i8* %45
br label %46
46: ; preds = %43, %40
%47 = tail call i32 @fclose(i32* %10)
%48 = tail call i64 @adler32(i8* %25, i64 %17)
%49 = trunc i64 %48 to i32
%50 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %49)
%51 = tail call i32 @free(i8* %25)
br label %58
52: ; preds = %12
%53 = load i32, i32* @stderr
%54 = tail call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %53)
br label %58
55: ; preds = %7
%56 = load i32, i32* @stderr
%57 = tail call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %19, %27, %34, %52, %55, %46, %4
%59 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %19 ], [ @EXIT_FAILURE, %27 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_SUCCESS, %46 ], [ @EXIT_FAILURE, %52 ], [ @EXIT_FAILURE, %55 ]
%60 = load i32, i32* %59
ret i32 %60
}