#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*/ ConvertFromDouble(double, unsigned char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int i;
  double val;
  unsigned char buf[8];
  val = 0.5;
  ConvertFromDouble(val, buf);
  fprintf(stdout, "val=%g\n", val);
  fprintf(stdout, "buf=");
  for (i = 0; i < 8; i++)
    fprintf(stdout, "%.2x", buf[i]);
  fprintf(stdout, "\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xec2(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
call   1040 <ConvertFromDouble@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
movsd  -0x20(%rbp),%xmm0
lea    0xea2(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11c3 <main+0xa3>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
movslq -0x14(%rbp),%rax
movzbl -0x28(%rbp,%rax,1),%edx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <main+0x6b>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movsd  0xed4(%rip),%xmm0
mov    %rsp,%rdi
call   1040 <ConvertFromDouble@plt>
mov    0x2ea5(%rip),%r14
mov    (%r14),%edi
lea    0xec3(%rip),%rsi
movsd  0xeb3(%rip),%xmm0
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    (%r14),%edi
lea    0xeb2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl (%rsp),%edx
lea    0xea2(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl 0x1(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl 0x2(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl 0x3(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl 0x4(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl 0x5(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl 0x6(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
movzbl 0x7(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
lea    0xe09(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [8 x i8] c"val=%g\0A\00"
@.str.1 = [5 x i8] c"buf=\00"
@.str.2 = [5 x i8] c"%.2x\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca [8 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 5.000000e-01, double* %7
%9 = load double, double* %7
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%11 = call i32 @ConvertFromDouble(double %9, i8* %10)
%12 = load i32, i32* @stdout
%13 = load double, double* %7
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %13)
%15 = load i32, i32* @stdout
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %17
17: ; preds = %28, %2
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 8
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i32, i32* @stdout
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %20
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %17
31: ; preds = %17
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [8 x i8] c"val=%g\0A\00"
@.str.1 = [5 x i8] c"buf=\00"
@.str.2 = [5 x i8] c"%.2x\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = call i32 @ConvertFromDouble(double 5.000000e-01, i8* %4)
%6 = load i32, i32* @stdout
%7 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double 5.000000e-01)
%8 = load i32, i32* @stdout
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stdout
%11 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @stdout
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @stdout
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @stdout
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stdout
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @stdout
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32, i32* @stdout
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* @stdout
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32, i32* @stdout
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}