#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__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ free(scalar_t__ *);
scalar_t__ malloc(unsigned int);
double omp_get_wtime();
int /*<<< orphan*/ rand();
double contig_htod() {
  extern unsigned int datasize;
  unsigned int i = 0;
  double t1_start = 0;
  double t1_end = 0;
  unsigned int n = (unsigned int)(datasize / sizeof(uint8_t));
  uint8_t *a = (uint8_t *)malloc(n * sizeof(uint8_t));
  if (a == NULL) {
    return (-10000);
  }
  for (i = 0; i < n; i++) {
    a[i] = (uint8_t)rand();
  }
  t1_start = omp_get_wtime();
#pragma acc data copyin(a [0:n])
  {
    if (n == 0) {
      a[0] = (uint8_t)1;
    }
  }
  t1_end = omp_get_wtime();
  free(a);
  return (t1_end - t1_start);
}


x86 assembly (clang, -O0):
<contig_htod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
shr    $0x3,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119e <contig_htod+0x5e>
movsd  0xe6c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1219 <contig_htod+0xd9>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    11d4 <contig_htod+0x94>
mov    $0x0,%al
call   1060 <rand@plt>
movslq %eax,%rdx
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a5 <contig_htod+0x65>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11f5 <contig_htod+0xb5>
mov    -0x30(%rbp),%rax
movq   $0x1,(%rax)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contig_htod>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e97(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%edi
and    $0xfffffff8,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117c <contig_htod+0x3c>
mov    %rax,%r15
cmp    $0x7,%r14d
ja     1186 <contig_htod+0x46>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
jmp    11c9 <contig_htod+0x89>
movsd  0xe7c(%rip),%xmm0
jmp    11f1 <contig_htod+0xb1>
mov    %r14d,%eax
shr    $0x3,%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovae %eax,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <contig_htod+0x60>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
cmp    $0x7,%r14d
ja     11d0 <contig_htod+0x90>
movq   $0x1,(%r15)
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@datasize = external global i32
define double @contig_htod() {
%1 = alloca double
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i64*
store i32 0, i32* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
%7 = load i32, i32* @datasize
%8 = zext i32 %7 to i64
%9 = udiv i64 %8, 8
%10 = trunc i64 %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i64*
store i64* %16, i64** %6
%17 = load i64*, i64** %6
%18 = icmp eq i64* %17, null
br i1 %18, label %19, label %20
19: ; preds = %0
store double -1.000000e+04, double* %1
br label %49
20: ; preds = %0
store i32 0, i32* %2
br label %21
21: ; preds = %32, %20
%22 = load i32, i32* %2
%23 = load i32, i32* %5
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = call i32 (...) @rand()
%27 = sext i32 %26 to i64
%28 = load i64*, i64** %6
%29 = load i32, i32* %2
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i64, i64* %28, i64 %30
store i64 %27, i64* %31
br label %32
32: ; preds = %25
%33 = load i32, i32* %2
%34 = add i32 %33, 1
store i32 %34, i32* %2
br label %21
35: ; preds = %21
%36 = call double (...) @omp_get_wtime()
store double %36, double* %3
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i64*, i64** %6
%41 = getelementptr inbounds i64, i64* %40, i64 0
store i64 1, i64* %41
br label %42
42: ; preds = %39, %35
%43 = call double (...) @omp_get_wtime()
store double %43, double* %4
%44 = load i64*, i64** %6
%45 = call i32 @free(i64* %44)
%46 = load double, double* %4
%47 = load double, double* %3
%48 = fsub double %46, %47
store double %48, double* %1
br label %49
49: ; preds = %42, %19
%50 = load double, double* %1
ret double %50
}

LLVM IR (-O2):
@datasize = external global i32
define double @contig_htod() {
%1 = load i32, i32* @datasize
%2 = lshr i32 %1, 3
%3 = and i32 %1, -8
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i64*
%6 = icmp eq i64 %4, 0
br i1 %6, label %30, label %7
7: ; preds = %0
%8 = icmp ult i32 %1, 8
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call double (...) @omp_get_wtime()
br label %23
11: ; preds = %7
%12 = call i32 @llvm.umax.i32(i32 %2, i32 1)
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %19, %14 ]
%16 = tail call i32 (...) @rand()
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %5, i64 %15
store i64 %17, i64* %18
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %13
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = tail call double (...) @omp_get_wtime()
br i1 %8, label %23, label %25
23: ; preds = %9, %21
%24 = phi double [ %10, %9 ], [ %22, %21 ]
store i64 1, i64* %5
br label %25
25: ; preds = %23, %21
%26 = phi double [ %24, %23 ], [ %22, %21 ]
%27 = tail call double (...) @omp_get_wtime()
%28 = tail call i32 @free(i64* %5)
%29 = fsub double %27, %26
br label %30
30: ; preds = %0, %25
%31 = phi double [ %29, %25 ], [ -1.000000e+04, %0 ]
ret double %31
}