double bits(x)
double x;
{
  union {
    double d;
    short i[4];
  } du;
  union {
    float f;
    short i[2];
  } df;
  int i;
  du.d = x;
  printf("double: ");
  for (i = 0; i < 4; i++)
    printf("0x%04x,", du.i[i] & 0xffff);
  printf("\n");
  df.f = (float)x;
  printf("float: ");
  for (i = 0; i < 2; i++)
    printf("0x%04x,", df.i[i] & 0xffff);
  printf("\n");
  return (x);
}


x86 assembly (clang, -O0):
<bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    1171 <bits+0x61>
movslq -0x1c(%rbp),%rax
movswl -0x10(%rbp,%rax,2),%esi
and    $0xffff,%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <bits+0x2c>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    11d7 <bits+0xc7>
movslq -0x1c(%rbp),%rax
movswl -0x18(%rbp,%rax,2),%esi
and    $0xffff,%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a2 <bits+0x92>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bits>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movq   0x8(%rsp),%xmm0
movq   %xmm0,%rbx
movzwl %bx,%esi
lea    0xeb9(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%esi
shr    $0x10,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
shr    $0x20,%rax
movzwl %ax,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
shr    $0x30,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x14(%rsp)
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movd   0x14(%rsp),%xmm0
movd   %xmm0,%ebx
movzwl %bx,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
shr    $0x10,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%union.anon = type { double }
%union.anon.0 = type { float }
@.str = [9 x i8] c"double: \00"
@.str.1 = [8 x i8] c"0x%04x,\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [8 x i8] c"float: \00"
define double @bits(double %0) {
%2 = alloca double
%3 = alloca %union.anon
%4 = alloca %union.anon.0
%5 = alloca i32
store double %0, double* %2
%6 = load double, double* %2
%7 = bitcast %union.anon* %3 to double*
store double %6, double* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %21, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = bitcast %union.anon* %3 to [4 x i16]*
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x i16], [4 x i16]* %13, i64 0, i64 %15
%17 = load i16, i16* %16
%18 = sext i16 %17 to i32
%19 = and i32 %18, 65535
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %12
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %9
24: ; preds = %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = load double, double* %2
%27 = fptrunc double %26 to float
%28 = bitcast %union.anon.0* %4 to float*
store float %27, float* %28
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %30
30: ; preds = %42, %24
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 2
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = bitcast %union.anon.0* %4 to [2 x i16]*
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [2 x i16], [2 x i16]* %34, i64 0, i64 %36
%38 = load i16, i16* %37
%39 = sext i16 %38 to i32
%40 = and i32 %39, 65535
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %33
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %30
45: ; preds = %30
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = load double, double* %2
ret double %47
}

LLVM IR (-O2):
@.str = [9 x i8] c"double: \00"
@.str.1 = [8 x i8] c"0x%04x,\00"
@.str.3 = [8 x i8] c"float: \00"
define double @bits(double returned %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = bitcast double %0 to i64
%4 = trunc i64 %3 to i32
%5 = and i32 %4, 65535
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = trunc i64 %3 to i32
%8 = lshr i32 %7, 16
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = lshr i64 %3, 32
%11 = trunc i64 %10 to i32
%12 = and i32 %11, 65535
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = lshr i64 %3, 48
%15 = trunc i64 %14 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @putchar(i32 10)
%18 = fptrunc double %0 to float
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%20 = bitcast float %18 to i32
%21 = and i32 %20, 65535
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = lshr i32 %20, 16
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = tail call i32 @putchar(i32 10)
ret double %0
}