#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int doMediaCheck(int, char *, char *, long long *, int *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int mediaCheckFile(char *file, int quiet) {
  int isofd;
  int rc;
  char *result;
  char mediasum[33], computedsum[33];
  long long isosize;
  int supported;
  isofd = open(file, O_RDONLY);
  if (isofd < 0) {
    fprintf(stderr, "Unable to find install image %s\n", file);
    return -1;
  }
  rc = doMediaCheck(isofd, mediasum, computedsum, &isosize, &supported, quiet);
  close(isofd);
  if (!quiet)
    fprintf(stderr, "The supported flag value is %d\n", supported);
  if (rc == 0)
    result = "FAIL.\n\nIt is not recommended to use this media.";
  else if (rc > 0)
    result = "PASS.\n\nIt is OK to install from this media.";
  else
    result =
        "NA.\n\nNo checksum information available, unable to verify media.";
  if (!quiet)
    fprintf(stderr,
            "The media check is complete, the "
            "result is: %s\n",
            result);
  return rc;
}


x86 assembly (clang, -O0):
<mediaCheckFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1198 <mediaCheckFile+0x58>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <mediaCheckFile+0x11b>
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x80(%rbp),%rdx
mov    -0x14(%rbp),%r9d
lea    -0x88(%rbp),%rcx
lea    -0x8c(%rbp),%r8
call   1030 <doMediaCheck@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11ec <mediaCheckFile+0xac>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x8c(%rbp),%edx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1206 <mediaCheckFile+0xc6>
lea    0xe44(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1230 <mediaCheckFile+0xf0>
cmpl   $0x0,-0x1c(%rbp)
jle    1220 <mediaCheckFile+0xe0>
lea    0xe5a(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    122b <mediaCheckFile+0xeb>
lea    0xe76(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1230 <mediaCheckFile+0xf0>
cmpl   $0x0,-0x14(%rbp)
jne    1255 <mediaCheckFile+0x115>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mediaCheckFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %esi,%r15d
mov    %rdi,%rbp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11de <mediaCheckFile+0x9e>
mov    %eax,%ebx
lea    0x40(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %eax,%edi
mov    %r15d,%r9d
call   1030 <doMediaCheck@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1040 <close@plt>
test   %r15d,%r15d
jne    11fe <mediaCheckFile+0xbe>
mov    0x2e40(%rip),%rbx
mov    (%rbx),%edi
mov    0x4(%rsp),%edx
lea    0xe7c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r14d,%r14d
lea    0xebb(%rip),%rax
lea    0xee0(%rip),%rcx
cmovg  %rax,%rcx
lea    0xe79(%rip),%rdx
cmovne %rcx,%rdx
mov    (%rbx),%edi
lea    0xf08(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11fe <mediaCheckFile+0xbe>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Unable to find install image %s\0A\00"
@.str.1 = [32 x i8] c"The supported flag value is %d\0A\00"
@.str.2 = [48 x i8] c"FAIL.\0A\0AIt is not recommended to use this media.\00"
@.str.3 = [44 x i8] c"PASS.\0A\0AIt is OK to install from this media.\00"
@.str.4 = [64 x i8] c"NA.\0A\0ANo checksum information available, unable to verify media.\00"
@.str.5 = [48 x i8] c"The media check is complete, the result is: %s\0A\00"
define i32 @mediaCheckFile(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [33 x i8]
%10 = alloca [33 x i8]
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = load i8*, i8** %4
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %4
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %55
22: ; preds = %2
%23 = load i32, i32* %6
%24 = getelementptr inbounds [33 x i8], [33 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds [33 x i8], [33 x i8]* %10, i64 0, i64 0
%26 = load i32, i32* %5
%27 = call i32 @doMediaCheck(i32 %23, i8* %24, i8* %25, i64* %11, i32* %12, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %22
%33 = load i32, i32* @stderr
%34 = load i32, i32* %12
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %22
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %36
store i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %46
40: ; preds = %36
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %45
44: ; preds = %40
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0), i8** %8
br label %45
45: ; preds = %44, %43
br label %46
46: ; preds = %45, %39
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %8
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %49, %46
%54 = load i32, i32* %7
store i32 %54, i32* %3
br label %55
55: ; preds = %53, %18
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Unable to find install image %s\0A\00"
@.str.1 = [32 x i8] c"The supported flag value is %d\0A\00"
@.str.2 = [48 x i8] c"FAIL.\0A\0AIt is not recommended to use this media.\00"
@.str.3 = [44 x i8] c"PASS.\0A\0AIt is OK to install from this media.\00"
@.str.4 = [64 x i8] c"NA.\0A\0ANo checksum information available, unable to verify media.\00"
@.str.5 = [48 x i8] c"The media check is complete, the result is: %s\0A\00"
define i32 @mediaCheckFile(i8* %0, i32 %1) {
%3 = alloca [33 x i8]
%4 = alloca [33 x i8]
%5 = alloca i64
%6 = alloca i32
%7 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%9 = bitcast i64* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %0, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %31
17: ; preds = %2
%18 = call i32 @doMediaCheck(i32 %12, i8* %7, i8* %8, i64* %5, i32* %6, i32 %1)
%19 = call i32 @close(i32 %12)
%20 = icmp eq i32 %1, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* %6
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = icmp eq i32 %18, 0
%26 = icmp sgt i32 %18, 0
%27 = select i1 %26, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0)
%28 = select i1 %25, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %27
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i8* %28)
br label %31
31: ; preds = %17, %21, %14
%32 = phi i32 [ -1, %14 ], [ %18, %21 ], [ %18, %17 ]
ret i32 %32
}