#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
void *malloc(int);
int /*<<< orphan*/ memcpy(float *, float *, int);
int /*<<< orphan*/ stderr;
void matrix_duplicate(float *src, float **dst, int matrix_dim) {
  int s = matrix_dim * matrix_dim * sizeof(float);
  float *p = (float *)({
    void *_tmp;
    if (!(_tmp = malloc(s))) {
      fprintf(stderr, "Allocation failed at %s:%d!\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/phrb/gpu-autotuning/refs/heads/master/"
              "src/rodinia_3.0/cuda/lud/common/common.c",
              192);
      exit(-1);
    }
    _tmp;
  });
  memcpy(p, src, s);
  *dst = p;
}


x86 assembly (clang, -O0):
<matrix_duplicate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a4 <matrix_duplicate+0x64>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
lea    0xe8d(%rip),%rdx
mov    $0xc0,%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_duplicate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
imul   %edx,%ebp
shl    $0x2,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117f <matrix_duplicate+0x3f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
lea    0xe87(%rip),%rdx
mov    $0xc0,%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Allocation failed at %s:%d!\0A\00"
@.str.1 = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/phrb/gpu-autotuning/refs/heads/master/src/rodinia_3.0/cuda/lud/common/common.c\00"
define void @matrix_duplicate(float* %0, float** %1, i32 %2) {
%4 = alloca float*
%5 = alloca float**
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca i8*
%10 = alloca i8*
store float* %0, float** %4
store float** %1, float*** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = load i32, i32* %6
%13 = mul nsw i32 %11, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = trunc i64 %15 to i32
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %24, label %20
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str.1, i64 0, i64 0), i32 192)
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %3
%25 = load i8*, i8** %9
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = bitcast i8* %26 to float*
store float* %27, float** %8
%28 = load float*, float** %8
%29 = load float*, float** %4
%30 = load i32, i32* %7
%31 = call i32 @memcpy(float* %28, float* %29, i32 %30)
%32 = load float*, float** %8
%33 = load float**, float*** %5
store float* %32, float** %33
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Allocation failed at %s:%d!\0A\00"
@.str.1 = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/phrb/gpu-autotuning/refs/heads/master/src/rodinia_3.0/cuda/lud/common/common.c\00"
define void @matrix_duplicate(float* %0, float** nocapture writeonly %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = mul i32 %4, %2
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str.1, i64 0, i64 0), i32 192)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %3
%13 = bitcast i8* %6 to float*
%14 = tail call i32 @memcpy(float* %13, float* %0, i32 %5)
%15 = bitcast float** %1 to i8**
store i8* %6, i8** %15
ret void
}