#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 */
struct elf_file_t {
  int dummy;
};

/* Variables and functions */
void *__xmalloc(int, char *);
struct elf_file_t *elf_file_create_from_allocated_buffer(void *, int, char *);
int /*<<< orphan*/ memcpy(void *, void *, int);
struct elf_file_t *elf_file_create_from_buffer(void *ptr, int size,
                                               char *name) {
  struct elf_file_t *elf_file;
  void *ptr_copy;
  ptr_copy = (__xmalloc(
      (size), "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/"
              "heads/HSA_Develop/m2s-rcsl/runtime/cuda/elf-format.c"
              ":"
              "589"));
  memcpy(ptr_copy, ptr, size);
  elf_file = elf_file_create_from_allocated_buffer(ptr_copy, size, name);
  return elf_file;
}


x86 assembly (clang, -O0):
<elf_file_create_from_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    0xeb3(%rip),%rsi
call   1040 <__xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <elf_file_create_from_allocated_buffer@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elf_file_create_from_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xeba(%rip),%rsi
mov    %ebp,%edi
call   1040 <__xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <elf_file_create_from_allocated_buffer@plt>

LLVM IR (-O0):
%struct.elf_file_t = type { i32 }
@.str = [181 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/HSA_Develop/m2s-rcsl/runtime/cuda/elf-format.c:589\00"
define %struct.elf_file_t* @elf_file_create_from_buffer(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.elf_file_t*
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %5
%10 = call i8* @__xmalloc(i32 %9, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = call i32 @memcpy(i8* %11, i8* %12, i32 %13)
%15 = load i8*, i8** %8
%16 = load i32, i32* %5
%17 = load i8*, i8** %6
%18 = call %struct.elf_file_t* @elf_file_create_from_allocated_buffer(i8* %15, i32 %16, i8* %17)
store %struct.elf_file_t* %18, %struct.elf_file_t** %7
%19 = load %struct.elf_file_t*, %struct.elf_file_t** %7
ret %struct.elf_file_t* %19
}

LLVM IR (-O2):
%struct.elf_file_t = type { i32 }
@.str = [181 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/HSA_Develop/m2s-rcsl/runtime/cuda/elf-format.c:589\00"
define %struct.elf_file_t* @elf_file_create_from_buffer(i8* %0, i32 %1, i8* %2) {
%4 = tail call i8* @__xmalloc(i32 %1, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @memcpy(i8* %4, i8* %0, i32 %1)
%6 = tail call %struct.elf_file_t* @elf_file_create_from_allocated_buffer(i8* %4, i32 %1, i8* %2)
ret %struct.elf_file_t* %6
}