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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ secPack(int, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void sendSecPack(int fd, const char *secfile) {
  if (!secfile) {
    fprintf(stderr, "No secpack specified, trying without.\n");
    return;
  }
  FILE *fp = fopen(secfile, "rb");
  if (!fp) {
    fprintf(stderr, "Can't open secpack: %s\n", strerror(errno));
    return;
  }
  char buffer[2048];
  if (fread(buffer, sizeof(buffer), 1, fp) != 1) {
    fprintf(stderr, "Can't read secpack: %s\n", strerror(errno));
    fclose(fp);
    return;
  }
  fclose(fp);
  secPack(fd, buffer);
}


x86 assembly (clang, -O0):
<sendSecPack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <sendSecPack+0x39>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    126e <sendSecPack+0x10e>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <sendSecPack+0x91>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x824(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x824(%rbp),%edi
mov    %rax,%rdx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    126e <sendSecPack+0x10e>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x800,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1256 <sendSecPack+0xf6>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x828(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x828(%rbp),%edi
mov    %rax,%rdx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    126e <sendSecPack+0x10e>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
call   1030 <secPack@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendSecPack>:
push   %rbp
push   %rbx
sub    $0x808,%rsp
test   %rsi,%rsi
je     11c0 <sendSecPack+0x60>
mov    %edi,%ebp
lea    0xeb0(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e0 <sendSecPack+0x80>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x800,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1213 <sendSecPack+0xb3>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1030 <secPack@plt>
add    $0x808,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%ebx
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe2c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fprintf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%ebp
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe11(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
add    $0x808,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"No secpack specified, trying without.\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Can't open secpack: %s\0A\00"
@errno = global i32 0
@.str.3 = [24 x i8] c"Can't read secpack: %s\0A\00"
define void @sendSecPack(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [2048 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %40
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %40
22: ; preds = %12
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%24 = load i32*, i32** %5
%25 = call i32 @fread(i8* %23, i32 2048, i32 1, i32* %24)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %5
%33 = call i32 @fclose(i32* %32)
br label %40
34: ; preds = %22
%35 = load i32*, i32** %5
%36 = call i32 @fclose(i32* %35)
%37 = load i32, i32* %3
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%39 = call i32 @secPack(i32 %37, i8* %38)
br label %40
40: ; preds = %34, %27, %17, %9
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"No secpack specified, trying without.\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Can't open secpack: %s\0A\00"
@errno = global i32 0
@.str.3 = [24 x i8] c"Can't read secpack: %s\0A\00"
define void @sendSecPack(i32 %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = icmp eq i8* %1, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %30
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %30
16: ; preds = %8
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%18 = call i32 @fread(i8* %17, i32 2048, i32 1, i32* %9)
%19 = icmp eq i32 %18, 1
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = tail call i32 @fclose(i32* %9)
br label %29
26: ; preds = %16
%27 = tail call i32 @fclose(i32* %9)
%28 = call i32 @secPack(i32 %0, i8* %17)
br label %29
29: ; preds = %26, %20
br label %30
30: ; preds = %11, %29, %5
ret void
}