#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int argi;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s {one or more file names ...}\n", argv[0]);
    exit(1);
  }
  for (argi = 1; argi < argc; argi++) {
    char first_four[4];
    FILE *fp;
    fp = fopen(argv[argi], "rb");
    if (fp == 0) {
      printf("Could not open file \"%s\" for binary read.\n", argv[argi]);
      continue;
    }
    if (fread(first_four, sizeof(char), 4, fp) != 4) {
      printf("Could not read first four bytes of file \"%s\".\n", argv[argi]);
    } else {
      if ((first_four[0] == 'A') && (first_four[1] == 'E') &&
          (first_four[2] == 'S') && (first_four[3] == 0)) {
        printf("AES file:      %s\n", argv[argi]);
      } else {
        printf("Non-AES file:  %s\n", argv[argi]);
      }
    }
    fclose(fp);
  }
  return 0;
}


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   $0x2,-0x8(%rbp)
jge    11a6 <main+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12bf <main+0x15f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe5c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fd <main+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
jmp    12b1 <main+0x151>
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
je     123a <main+0xda>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
jmp    12a8 <main+0x148>
movsbl -0x18(%rbp),%eax
cmp    $0x41,%eax
jne    128b <main+0x12b>
movsbl -0x17(%rbp),%eax
cmp    $0x45,%eax
jne    128b <main+0x12b>
movsbl -0x16(%rbp),%eax
cmp    $0x53,%eax
jne    128b <main+0x12b>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jne    128b <main+0x12b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
jmp    12a3 <main+0x143>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
jmp    12a8 <main+0x148>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <main+0x4d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     1237 <main+0xd7>
mov    %edi,%r13d
mov    $0x1,%r15d
lea    0xea1(%rip),%r14
lea    0x4(%rsp),%r12
jmp    11a9 <main+0x49>
xchg   %ax,%ax
mov    (%rbx,%r15,8),%rsi
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     1226 <main+0xc6>
mov    (%rbx,%r15,8),%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1190 <main+0x30>
mov    %rax,%rbp
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    1200 <main+0xa0>
movd   0x4(%rsp),%xmm0
movd   %xmm0,%eax
mov    (%rbx,%r15,8),%rsi
cmp    $0x534541,%eax
jne    120d <main+0xad>
lea    0xe92(%rip),%rdi
jmp    1214 <main+0xb4>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%r15,8),%rsi
lea    0xe4b(%rip),%rdi
jmp    1214 <main+0xb4>
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    11a0 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdb6(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s {one or more file names ...}\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [43 x i8] c"Could not open file \22%s\22 for binary read.\0A\00"
@.str.3 = [47 x i8] c"Could not read first four bytes of file \22%s\22.\0A\00"
@.str.4 = [19 x i8] c"AES file: %s\0A\00"
@.str.5 = [19 x i8] c"Non-AES file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4 x i8]
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i32 1, i32* %6
br label %19
19: ; preds = %89, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %92
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = load i32, i32* %6
%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 ([3 x i8], [3 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 %39
32: ; preds = %23
%33 = load i8**, i8*** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %89
39: ; preds = %23
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%41 = load i32*, i32** %8
%42 = call i32 @fread(i8* %40, i32 1, i32 4, i32* %41)
%43 = icmp ne i32 %42, 4
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load i8**, i8*** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %49)
br label %86
51: ; preds = %39
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 65
br i1 %55, label %56, label %78
56: ; preds = %51
%57 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 1
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 69
br i1 %60, label %61, label %78
61: ; preds = %56
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 2
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 83
br i1 %65, label %66, label %78
66: ; preds = %61
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 3
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %66
%72 = load i8**, i8*** %5
%73 = load i32, i32* %6
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %76)
br label %85
78: ; preds = %66, %61, %56, %51
%79 = load i8**, i8*** %5
%80 = load i32, i32* %6
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %79, i64 %81
%83 = load i8*, i8** %82
%84 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %83)
br label %85
85: ; preds = %78, %71
br label %86
86: ; preds = %85, %44
%87 = load i32*, i32** %8
%88 = call i32 @fclose(i32* %87)
br label %89
89: ; preds = %86, %32
%90 = load i32, i32* %6
%91 = add nsw i32 %90, 1
store i32 %91, i32* %6
br label %19
92: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s {one or more file names ...}\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [43 x i8] c"Could not open file \22%s\22 for binary read.\0A\00"
@.str.3 = [47 x i8] c"Could not read first four bytes of file \22%s\22.\0A\00"
@.str.4 = [19 x i8] c"AES file: %s\0A\00"
@.str.5 = [19 x i8] c"Non-AES file: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca <4 x i8>
%4 = icmp slt i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = getelementptr inbounds <4 x i8>, <4 x i8>* %3, i64 0, i64 0
%7 = zext i32 %0 to i64
br label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %5, %40
%14 = phi i64 [ 1, %5 ], [ %41, %40 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i8*, i8** %15
%21 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %40
22: ; preds = %13
%23 = call i32 @fread(i8* %6, i32 1, i32 4, i32* %17)
%24 = icmp eq i32 %23, 4
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8*, i8** %15
%27 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %38
28: ; preds = %22
%29 = load <4 x i8>, <4 x i8>* %3
%30 = freeze <4 x i8> %29
%31 = bitcast <4 x i8> %30 to i32
%32 = icmp eq i32 %31, 5457217
%33 = load i8*, i8** %15
br i1 %32, label %34, label %36
34: ; preds = %28
%35 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %38
36: ; preds = %28
%37 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %33)
br label %38
38: ; preds = %34, %36, %25
%39 = tail call i32 @fclose(i32* %17)
br label %40
40: ; preds = %38, %19
%41 = add nuw nsw i64 %14, 1
%42 = icmp eq i64 %41, %7
br i1 %42, label %43, label %13
43: ; preds = %40
ret i32 0
}