#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*/ bzero(char *, size_t);
char *malloc(size_t);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *recv_secret(void) {
  size_t len;
  char *secret = "Rosebud? A sled.";
  char *dsecret;
  len = ((strlen(secret) + 1) * sizeof(char));
  if ((dsecret = malloc(len)) == NULL) {
    return NULL;
  }
  bzero(dsecret, len);
  strncpy(dsecret, secret, len - 1);
  return dsecret;
}


x86 assembly (clang, -O0):
<recv_secret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    118d <recv_secret+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11b7 <recv_secret+0x77>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <bzero@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_secret>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1187 <recv_secret+0x47>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <bzero@plt>
add    $0xffffffffffffffff,%rbx
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Rosebud? A sled.\00"
define i8* @recv_secret() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 1
store i64 %9, i64* %2
%10 = load i64, i64* %2
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %0
store i8* null, i8** %1
br label %24
14: ; preds = %0
%15 = load i8*, i8** %4
%16 = load i64, i64* %2
%17 = call i32 @bzero(i8* %15, i64 %16)
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = load i64, i64* %2
%21 = sub i64 %20, 1
%22 = call i32 @strncpy(i8* %18, i8* %19, i64 %21)
%23 = load i8*, i8** %4
store i8* %23, i8** %1
br label %24
24: ; preds = %14, %13
%25 = load i8*, i8** %1
ret i8* %25
}

LLVM IR (-O2):
@.str = [17 x i8] c"Rosebud? A sled.\00"
define i8* @recv_secret() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%2 = add nsw i32 %1, 1
%3 = sext i32 %2 to i64
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = tail call i32 @bzero(i8* %4, i64 %3)
%8 = add nsw i64 %3, -1
%9 = tail call i32 @strncpy(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %8)
br label %10
10: ; preds = %0, %6
ret i8* %4
}