#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ bitwise_itobin(int, char *);
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ union_itobin(int, char *);
int main() {
  char s[sizeof(int) * 8 + 1];
  for (unsigned char i = 0; i < sizeof(int) * 8; i++)
    s[i] = 'a';
  s[sizeof(int) * 8] = 0;
  clock_t begin = clock();
  for (int i = -(1 << 24); i < 1 << 24; i++)
    union_itobin(i, s);
  clock_t end = clock();
  double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("union fxn: %f seconds\n", time_spent);
  begin = clock();
  for (int i = -(1 << 24); i < 1 << 24; i++)
    bitwise_itobin(i, s);
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("bitwise fxn: %f seconds\n", time_spent);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x31(%rbp)
movzbl -0x31(%rbp),%eax
cmp    $0x20,%rax
jae    1177 <main+0x37>
movzbl -0x31(%rbp),%eax
movb   $0x61,-0x30(%rbp,%rax,1)
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    1153 <main+0x13>
movb   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x40(%rbp)
movl   $0xff000000,-0x44(%rbp)
cmpl   $0x1000000,-0x44(%rbp)
jge    11b4 <main+0x74>
mov    -0x44(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <union_itobin@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118d <main+0x4d>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e15(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
lea    0xe18(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x40(%rbp)
movl   $0xff000000,-0x5c(%rbp)
cmpl   $0x1000000,-0x5c(%rbp)
jge    1226 <main+0xe6>
mov    -0x5c(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <bitwise_itobin@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11ff <main+0xbf>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2da3(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
lea    0xdbd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movb   $0x0,0x20(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    $0xff000000,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <union_itobin@plt>
add    $0x1,%ebp
cmp    $0x1000000,%ebp
jne    1180 <main+0x40>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e3a(%rip),%r15
divsd  (%r15),%xmm0
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    $0xff000000,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <bitwise_itobin@plt>
add    $0x1,%ebp
cmp    $0x1000000,%ebp
jne    11e0 <main+0xa0>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [23 x i8] c"union fxn: %f seconds\0A\00"
@.str.1 = [25 x i8] c"bitwise fxn: %f seconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [33 x i8]
%3 = alloca i8
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
store i8 0, i8* %3
br label %9
9: ; preds = %17, %0
%10 = load i8, i8* %3
%11 = zext i8 %10 to i64
%12 = icmp ult i64 %11, 32
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i8, i8* %3
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 %15
store i8 97, i8* %16
br label %17
17: ; preds = %13
%18 = load i8, i8* %3
%19 = add i8 %18, 1
store i8 %19, i8* %3
br label %9
20: ; preds = %9
%21 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 32
store i8 0, i8* %21
%22 = call i64 (...) @clock()
store i64 %22, i64* %4
store i32 -16777216, i32* %5
br label %23
23: ; preds = %30, %20
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 16777216
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %5
%28 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 0
%29 = call i32 @union_itobin(i32 %27, i8* %28)
br label %30
30: ; preds = %26
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %23
33: ; preds = %23
%34 = call i64 (...) @clock()
store i64 %34, i64* %6
%35 = load i64, i64* %6
%36 = load i64, i64* %4
%37 = sub nsw i64 %35, %36
%38 = sitofp i64 %37 to double
%39 = load double, double* @CLOCKS_PER_SEC
%40 = fdiv double %38, %39
store double %40, double* %7
%41 = load double, double* %7
%42 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), double %41)
%43 = call i64 (...) @clock()
store i64 %43, i64* %4
store i32 -16777216, i32* %8
br label %44
44: ; preds = %51, %33
%45 = load i32, i32* %8
%46 = icmp slt i32 %45, 16777216
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i32, i32* %8
%49 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 0
%50 = call i32 @bitwise_itobin(i32 %48, i8* %49)
br label %51
51: ; preds = %47
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %44
54: ; preds = %44
%55 = call i64 (...) @clock()
store i64 %55, i64* %6
%56 = load i64, i64* %6
%57 = load i64, i64* %4
%58 = sub nsw i64 %56, %57
%59 = sitofp i64 %58 to double
%60 = load double, double* @CLOCKS_PER_SEC
%61 = fdiv double %59, %60
store double %61, double* %7
%62 = load double, double* %7
%63 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %62)
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [23 x i8] c"union fxn: %f seconds\0A\00"
@.str.1 = [25 x i8] c"bitwise fxn: %f seconds\0A\00"
define i32 @main() {
%1 = alloca [33 x i8]
%2 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 32
store i8 0, i8* %4
%5 = tail call i64 (...) @clock()
br label %14
6: ; preds = %14
%7 = call i64 (...) @clock()
%8 = sub nsw i64 %7, %5
%9 = sitofp i64 %8 to double
%10 = load double, double* @CLOCKS_PER_SEC
%11 = fdiv double %9, %10
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), double %11)
%13 = call i64 (...) @clock()
br label %26
14: ; preds = %0, %14
%15 = phi i32 [ -16777216, %0 ], [ %17, %14 ]
%16 = call i32 @union_itobin(i32 %15, i8* %3)
%17 = add nsw i32 %15, 1
%18 = icmp eq i32 %17, 16777216
br i1 %18, label %6, label %14
19: ; preds = %26
%20 = call i64 (...) @clock()
%21 = sub nsw i64 %20, %13
%22 = sitofp i64 %21 to double
%23 = load double, double* @CLOCKS_PER_SEC
%24 = fdiv double %22, %23
%25 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %24)
ret i32 0
26: ; preds = %6, %26
%27 = phi i32 [ -16777216, %6 ], [ %29, %26 ]
%28 = call i32 @bitwise_itobin(i32 %27, i8* %3)
%29 = add nsw i32 %27, 1
%30 = icmp eq i32 %29, 16777216
br i1 %30, label %19, label %26
}