#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
int /*<<< orphan*/ sendCertificate(int /*<<< orphan*/, unsigned char *, long);
int /*<<< orphan*/ snprintf(char *, int, char *);
int multosDeleteApp(char *adcFile, char *error, int errBuffLen) {
  FILE *fp;
  long adcSize;
  unsigned char *adc;
  int status = 1;
  fp = fopen(adcFile, "rb");
  if (fp == NULL) {
    if (error)
      snprintf(error, errBuffLen - 1, "Failed to open ADC\n");
    return (0);
  }
  fseek(fp, 0, 2);
  adcSize = ftell(fp);
  fseek(fp, 0, 0);
  adc = (unsigned char *)malloc(adcSize);
  if (adc == NULL) {
    if (error)
      snprintf(error, errBuffLen - 1, "Failed to read ADC\n");
    return (0);
  }
  fread(adc, 1, adcSize, fp);
  fclose(fp);
  if (!sendCertificate(0, adc, adcSize)) {
    status = 0;
    if (error)
      snprintf(error, errBuffLen - 1, "ADC loading failed\n");
  }
  free(adc);
  return (status);
}


x86 assembly (clang, -O0):
<multosDeleteApp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f6 <multosDeleteApp+0x66>
cmpq   $0x0,-0x18(%rbp)
je     11ea <multosDeleteApp+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
lea    0xe1e(%rip),%rdx
call   1070 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d8 <multosDeleteApp+0x148>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1265 <multosDeleteApp+0xd5>
cmpq   $0x0,-0x18(%rbp)
je     1259 <multosDeleteApp+0xc9>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
lea    0xdc3(%rip),%rdx
call   1070 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d8 <multosDeleteApp+0x148>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
xor    %edi,%edi
call   1060 <sendCertificate@plt>
cmp    $0x0,%eax
jne    12c9 <multosDeleteApp+0x139>
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12c4 <multosDeleteApp+0x134>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
lea    0xd6c(%rip),%rdx
call   1070 <snprintf@plt>
jmp    12c9 <multosDeleteApp+0x139>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multosDeleteApp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
lea    0xe58(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     124c <multosDeleteApp+0xbc>
mov    %rax,%rbp
xor    %r12d,%r12d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10a0 <fseek@plt>
mov    %rbp,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     1261 <multosDeleteApp+0xd1>
mov    %rax,%r13
mov    $0x1,%r12d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <sendCertificate@plt>
test   %eax,%eax
jne    1242 <multosDeleteApp+0xb2>
test   %r14,%r14
je     123f <multosDeleteApp+0xaf>
add    $0xffffffff,%r15d
lea    0xdf7(%rip),%rdx
mov    %r14,%rdi
mov    %r15d,%esi
call   1070 <snprintf@plt>
xor    %r12d,%r12d
mov    %r13,%rdi
call   1030 <free@plt>
jmp    127c <multosDeleteApp+0xec>
xor    %r12d,%r12d
test   %r14,%r14
je     127c <multosDeleteApp+0xec>
add    $0xffffffff,%r15d
lea    0xda4(%rip),%rdx
jmp    1271 <multosDeleteApp+0xe1>
test   %r14,%r14
je     127c <multosDeleteApp+0xec>
add    $0xffffffff,%r15d
lea    0xda6(%rip),%rdx
mov    %r14,%rdi
mov    %r15d,%esi
call   1070 <snprintf@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [20 x i8] c"Failed to open ADC\0A\00"
@.str.2 = [20 x i8] c"Failed to read ADC\0A\00"
@.str.3 = [20 x i8] c"ADC loading failed\0A\00"
define i32 @multosDeleteApp(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 1, i32* %11
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %25
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 1
%23 = call i32 @snprintf(i8* %20, i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %19, %16
store i32 0, i32* %4
br label %70
25: ; preds = %3
%26 = load i32*, i32** %8
%27 = call i32 @fseek(i32* %26, i32 0, i32 2)
%28 = load i32*, i32** %8
%29 = call i64 @ftell(i32* %28)
store i64 %29, i64* %9
%30 = load i32*, i32** %8
%31 = call i32 @fseek(i32* %30, i32 0, i32 0)
%32 = load i64, i64* %9
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %10
%35 = load i8*, i8** %10
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %46
37: ; preds = %25
%38 = load i8*, i8** %6
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i8*, i8** %6
%42 = load i32, i32* %7
%43 = sub nsw i32 %42, 1
%44 = call i32 @snprintf(i8* %41, i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %40, %37
store i32 0, i32* %4
br label %70
46: ; preds = %25
%47 = load i8*, i8** %10
%48 = load i64, i64* %9
%49 = load i32*, i32** %8
%50 = call i32 @fread(i8* %47, i32 1, i64 %48, i32* %49)
%51 = load i32*, i32** %8
%52 = call i32 @fclose(i32* %51)
%53 = load i8*, i8** %10
%54 = load i64, i64* %9
%55 = call i32 @sendCertificate(i32 0, i8* %53, i64 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %66, label %57
57: ; preds = %46
store i32 0, i32* %11
%58 = load i8*, i8** %6
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i8*, i8** %6
%62 = load i32, i32* %7
%63 = sub nsw i32 %62, 1
%64 = call i32 @snprintf(i8* %61, i32 %63, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %60, %57
br label %66
66: ; preds = %65, %46
%67 = load i8*, i8** %10
%68 = call i32 @free(i8* %67)
%69 = load i32, i32* %11
store i32 %69, i32* %4
br label %70
70: ; preds = %66, %45, %24
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [20 x i8] c"Failed to open ADC\0A\00"
@.str.2 = [20 x i8] c"Failed to read ADC\0A\00"
@.str.3 = [20 x i8] c"ADC loading failed\0A\00"
define i32 @multosDeleteApp(i8* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = icmp eq i8* %1, null
br i1 %7, label %36, label %8
8: ; preds = %6
%9 = add nsw i32 %2, -1
%10 = tail call i32 @snprintf(i8* %1, i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %36
11: ; preds = %3
%12 = tail call i32 @fseek(i32* %4, i32 0, i32 2)
%13 = tail call i64 @ftell(i32* %4)
%14 = tail call i32 @fseek(i32* %4, i32 0, i32 0)
%15 = tail call i64 @malloc(i64 %13)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = icmp eq i8* %1, null
br i1 %19, label %36, label %20
20: ; preds = %18
%21 = add nsw i32 %2, -1
%22 = tail call i32 @snprintf(i8* %1, i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %36
23: ; preds = %11
%24 = tail call i32 @fread(i8* %16, i32 1, i64 %13, i32* %4)
%25 = tail call i32 @fclose(i32* %4)
%26 = tail call i32 @sendCertificate(i32 0, i8* %16, i64 %13)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = icmp eq i8* %1, null
br i1 %29, label %33, label %30
30: ; preds = %28
%31 = add nsw i32 %2, -1
%32 = tail call i32 @snprintf(i8* %1, i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %28, %30, %23
%34 = phi i32 [ 1, %23 ], [ 0, %30 ], [ 0, %28 ]
%35 = tail call i32 @free(i8* %16)
br label %36
36: ; preds = %18, %20, %6, %8, %33
%37 = phi i32 [ %34, %33 ], [ 0, %8 ], [ 0, %6 ], [ 0, %20 ], [ 0, %18 ]
ret i32 %37
}