#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 *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int mediaCheckFile(char *file, int quiet) {
  int isofd;
  int rc;
  char *result;
  unsigned 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, (char *)mediasum, (char *)computedsum, &isosize,
                    &supported, quiet);
  close(isofd);
  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    1196 <mediaCheckFile+0x56>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <mediaCheckFile+0xf0>
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,-0x1c(%rbp)
jne    11dd <mediaCheckFile+0x9d>
lea    0xe4d(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1207 <mediaCheckFile+0xc7>
cmpl   $0x0,-0x1c(%rbp)
jle    11f7 <mediaCheckFile+0xb7>
lea    0xe63(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1202 <mediaCheckFile+0xc2>
lea    0xe7f(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1207 <mediaCheckFile+0xc7>
cmpl   $0x0,-0x14(%rbp)
jne    122a <mediaCheckFile+0xea>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe98(%rip),%rsi
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     11c8 <mediaCheckFile+0x88>
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    11e6 <mediaCheckFile+0xa6>
test   %r14d,%r14d
lea    0xeb6(%rip),%rax
lea    0xedb(%rip),%rcx
cmovg  %rax,%rcx
lea    0xe74(%rip),%rdx
cmovne %rcx,%rdx
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xefc(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11e6 <mediaCheckFile+0xa6>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    %rbp,%rdx
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 = [48 x i8] c"FAIL.\0A\0AIt is not recommended to use this media.\00"
@.str.2 = [44 x i8] c"PASS.\0A\0AIt is OK to install from this media.\00"
@.str.3 = [64 x i8] c"NA.\0A\0ANo checksum information available, unable to verify media.\00"
@.str.4 = [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 @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 %48
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* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %22
store i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %39
33: ; preds = %22
%34 = load i32, i32* %7
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %38
37: ; preds = %33
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %38
38: ; preds = %37, %36
br label %39
39: ; preds = %38, %32
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %8
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %39
%47 = load i32, i32* %7
store i32 %47, i32* %3
br label %48
48: ; preds = %46, %18
%49 = load i32, i32* %3
ret i32 %49
}

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 = [48 x i8] c"FAIL.\0A\0AIt is not recommended to use this media.\00"
@.str.2 = [44 x i8] c"PASS.\0A\0AIt is OK to install from this media.\00"
@.str.3 = [64 x i8] c"NA.\0A\0ANo checksum information available, unable to verify media.\00"
@.str.4 = [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 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %28
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 %28
21: ; preds = %17
%22 = icmp eq i32 %18, 0
%23 = icmp sgt i32 %18, 0
%24 = select i1 %23, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0)
%25 = select i1 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %24
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %28
28: ; preds = %17, %21, %14
%29 = phi i32 [ -1, %14 ], [ %18, %21 ], [ %18, %17 ]
ret i32 %29
}