#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*/ EX_OSERR;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
char *malloc(int);
size_t strlen(char const *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *core_of_prog(const char *filename) {
  char *corefile;
  size_t len;
  len = strlen(filename);
  if (!(corefile = malloc(sizeof(char) * (len + 6))))
    err(EX_OSERR, "could not malloc corefile name");
  strncpy(corefile, filename, len);
  strncat(corefile, ".core", 5);
  return corefile;
}


x86 assembly (clang, -O0):
<core_of_prog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x6,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    119f <core_of_prog+0x4f>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1060 <err@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe64(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<core_of_prog>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0x6(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1185 <core_of_prog+0x35>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1060 <err@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1050 <strncat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EX_OSERR = global i32 0
@.str = [31 x i8] c"could not malloc corefile name\00"
@.str.1 = [6 x i8] c".core\00"
define i8* @core_of_prog(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = add i64 %7, 6
%9 = mul i64 1, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i32, i32* @EX_OSERR
%15 = call i32 @err(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %1
%17 = load i8*, i8** %3
%18 = load i8*, i8** %2
%19 = load i64, i64* %4
%20 = call i32 @strncpy(i8* %17, i8* %18, i64 %19)
%21 = load i8*, i8** %3
%22 = call i32 @strncat(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@EX_OSERR = global i32 0
@.str = [31 x i8] c"could not malloc corefile name\00"
@.str.1 = [6 x i8] c".core\00"
define i8* @core_of_prog(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 6
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @EX_OSERR
%9 = tail call i32 @err(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = tail call i32 @strncpy(i8* %5, i8* %0, i64 %2)
%12 = tail call i32 @strncat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
ret i8* %5
}