#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*/ cov_serialize(long double, unsigned char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
unsigned char *malloc(int);
scalar_t__ strlen(char *);
void cov_log(long double ld, char *msg, char *fn) {
  int ld_size, i;
  unsigned char *buf;
  FILE *file;
  file = fopen(fn, "a");
  ld_size = 10;
  buf = malloc(ld_size);
  if (strlen(msg) > 0)
    fprintf(file, "#%s\n", msg);
  cov_serialize(ld, buf, ld_size);
  for (i = 0; i < ld_size; i++) {
    fprintf(file, "%02X", buf[i]);
  }
  fprintf(file, "\n");
  fclose(file);
}


x86 assembly (clang, -O0):
<cov_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0xa,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11c6 <cov_log+0x66>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
fldt   -0x10(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    %rsp,%rax
fstpt  (%rax)
call   1080 <cov_serialize@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1219 <cov_log+0xb9>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e1 <cov_log+0x81>
mov    -0x38(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cov_log>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rax
mov    %rdi,%r15
fldt   0x40(%rsp)
fstpt  0x14(%rsp)
lea    0xe72(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    11c7 <cov_log+0x57>
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
fldt   0x14(%rsp)
fstpt  (%rsp)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1090 <cov_serialize@plt>
movzbl (%rbx),%edx
lea    0xe22(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x1(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x2(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x3(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x4(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x5(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x6(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x7(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x8(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movzbl 0x9(%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [5 x i8] c"#%s\0A\00"
@.str.2 = [5 x i8] c"%02X\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @cov_log(x86_fp80 %0, i8* %1, i8* %2) {
%4 = alloca x86_fp80
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
store x86_fp80 %0, x86_fp80* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %6
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
store i32 10, i32* %7
%13 = load i32, i32* %7
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %9
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32*, i32** %10
%20 = load i8*, i8** %5
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %3
%23 = load x86_fp80, x86_fp80* %4
%24 = load i8*, i8** %9
%25 = load i32, i32* %7
%26 = call i32 @cov_serialize(x86_fp80 %23, i8* %24, i32 %25)
store i32 0, i32* %8
br label %27
27: ; preds = %40, %22
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i32*, i32** %10
%33 = load i8*, i8** %9
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %31
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %27
43: ; preds = %27
%44 = load i32*, i32** %10
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32*, i32** %10
%47 = call i32 @fclose(i32* %46)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [5 x i8] c"#%s\0A\00"
@.str.2 = [5 x i8] c"%02X\00"
define void @cov_log(x86_fp80 %0, i8* %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %10
10: ; preds = %8, %3
%11 = tail call i32 @cov_serialize(x86_fp80 %0, i8* %5, i32 10)
%12 = load i8, i8* %5
%13 = zext i8 %12 to i32
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds i8, i8* %5, i64 1
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds i8, i8* %5, i64 2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i8, i8* %5, i64 3
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds i8, i8* %5, i64 4
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds i8, i8* %5, i64 5
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds i8, i8* %5, i64 6
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds i8, i8* %5, i64 7
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds i8, i8* %5, i64 8
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds i8, i8* %5, i64 9
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = tail call i32 @fputc(i32 10, i32* %4)
%52 = tail call i32 @fclose(i32* %4)
ret void
}