#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 */
size_t find_type_len(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
size_t extract_type_to_string(char **dst, const char *src) {
  size_t len = find_type_len(src, strlen(src));
  *dst = malloc(len + 1);
  if (NULL == *dst) {
    fprintf(stderr, "ERROR: Out of memory while allocating argument type\n");
    return 0;
  }
  memset(*dst, 0, len + 1);
  strncpy(*dst, src, len);
  return len;
}


x86 assembly (clang, -O0):
<extract_type_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1060 <find_type_len@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    11d8 <extract_type_to_string+0x78>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    120a <extract_type_to_string+0xaa>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_type_to_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <find_type_len@plt>
mov    %rax,%rbx
lea    0x1(%rax),%r12
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11b4 <extract_type_to_string+0x54>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1050 <memset@plt>
mov    (%r15),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
jmp    11cb <extract_type_to_string+0x6b>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1070 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"ERROR: Out of memory while allocating argument type\0A\00"
define i64 @extract_type_to_string(i8** %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
store i8** %0, i8*** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = call i64 @find_type_len(i8* %7, i32 %9)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = add i64 %11, 1
%13 = call i8* @malloc(i64 %12)
%14 = load i8**, i8*** %4
store i8* %13, i8** %14
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
%17 = icmp eq i8* null, %16
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %3
br label %33
21: ; preds = %2
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i64, i64* %6
%25 = add i64 %24, 1
%26 = call i32 @memset(i8* %23, i32 0, i64 %25)
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = call i32 @strncpy(i8* %28, i8* %29, i64 %30)
%32 = load i64, i64* %6
store i64 %32, i64* %3
br label %33
33: ; preds = %21, %18
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"ERROR: Out of memory while allocating argument type\0A\00"
define i64 @extract_type_to_string(i8** nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i64 @find_type_len(i8* %1, i32 %3)
%5 = add i64 %4, 1
%6 = tail call i8* @malloc(i64 %5)
store i8* %6, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %2
%12 = tail call i32 @memset(i8* %6, i32 0, i64 %5)
%13 = load i8*, i8** %0
%14 = tail call i32 @strncpy(i8* %13, i8* %1, i64 %4)
br label %15
15: ; preds = %11, %8
%16 = phi i64 [ 0, %8 ], [ %4, %11 ]
ret i64 %16
}