#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 */
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int strlen(char const *);
int make_mtllib_key(char const *mtllib, char const *name, void **key,
                    size_t *size) {
  char *p, *q;
  size_t fsz, nsz, qsz, sz;
  q = "mtllib";
  fsz = strlen(mtllib) + 1;
  nsz = strlen(name) + 1;
  qsz = strlen(q) + 1;
  sz = fsz + nsz + qsz;
  p = malloc(sz);
  if (!sz) {
    return -1;
  }
  (void)memcpy(p, q, qsz);
  (void)memcpy(p + qsz, name, nsz);
  (void)memcpy(p + qsz + nsz, mtllib, fsz);
  *key = p;
  *size = sz;
  return 0;
}


x86 assembly (clang, -O0):
<make_mtllib_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
add    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    11bd <make_mtllib_key+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <make_mtllib_key+0xe9>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    -0x50(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_mtllib_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,0x20(%rsp)
mov    %rsi,%rbp
mov    %rdi,0x18(%rsp)
call   1030 <strlen@plt>
movslq %eax,%rbx
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
lea    0xe93(%rip),%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
add    $0x1,%r15
lea    (%rbx,%rbp,1),%r13
add    $0x2,%r13
lea    (%r15,%r13,1),%rdi
call   1050 <malloc@plt>
add    %r15,%r13
je     11ee <make_mtllib_key+0xbe>
mov    %rax,%r12
add    $0x1,%rbx
add    $0x1,%rbp
lea    0xe5f(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1040 <memcpy@plt>
mov    %r14,0x8(%rsp)
mov    %r12,%r14
add    %r15,%r14
mov    %r14,%rdi
mov    0x10(%rsp),%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
add    %rbp,%r14
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    0x20(%rsp),%rax
mov    %r12,(%rax)
mov    0x8(%rsp),%rax
mov    %r13,(%rax)
xor    %eax,%eax
jmp    11f3 <make_mtllib_key+0xc3>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"mtllib\00"
define i32 @make_mtllib_key(i8* %0, i8* %1, i8** %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %11
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
store i64 %19, i64* %12
%20 = load i8*, i8** %7
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
store i64 %23, i64* %13
%24 = load i8*, i8** %11
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
store i64 %27, i64* %14
%28 = load i64, i64* %12
%29 = load i64, i64* %13
%30 = add i64 %28, %29
%31 = load i64, i64* %14
%32 = add i64 %30, %31
store i64 %32, i64* %15
%33 = load i64, i64* %15
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %10
%35 = load i64, i64* %15
%36 = icmp ne i64 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %4
store i32 -1, i32* %5
br label %61
38: ; preds = %4
%39 = load i8*, i8** %10
%40 = load i8*, i8** %11
%41 = load i64, i64* %14
%42 = call i32 @memcpy(i8* %39, i8* %40, i64 %41)
%43 = load i8*, i8** %10
%44 = load i64, i64* %14
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8*, i8** %7
%47 = load i64, i64* %13
%48 = call i32 @memcpy(i8* %45, i8* %46, i64 %47)
%49 = load i8*, i8** %10
%50 = load i64, i64* %14
%51 = getelementptr inbounds i8, i8* %49, i64 %50
%52 = load i64, i64* %13
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = load i8*, i8** %6
%55 = load i64, i64* %12
%56 = call i32 @memcpy(i8* %53, i8* %54, i64 %55)
%57 = load i8*, i8** %10
%58 = load i8**, i8*** %8
store i8* %57, i8** %58
%59 = load i64, i64* %15
%60 = load i64*, i64** %9
store i64 %59, i64* %60
store i32 0, i32* %5
br label %61
61: ; preds = %38, %37
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
@.str = [7 x i8] c"mtllib\00"
define i32 @make_mtllib_key(i8* %0, i8* %1, i8** nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = tail call i32 @strlen(i8* %1)
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = add nsw i64 %10, %7
%15 = add nsw i64 %14, %13
%16 = tail call i8* @malloc(i64 %15)
%17 = icmp eq i64 %15, 0
br i1 %17, label %24, label %18
18: ; preds = %4
%19 = tail call i32 @memcpy(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %13)
%20 = getelementptr inbounds i8, i8* %16, i64 %13
%21 = tail call i32 @memcpy(i8* %20, i8* %1, i64 %10)
%22 = getelementptr inbounds i8, i8* %20, i64 %10
%23 = tail call i32 @memcpy(i8* %22, i8* %0, i64 %7)
store i8* %16, i8** %2
store i64 %15, i64* %3
br label %24
24: ; preds = %4, %18
%25 = phi i32 [ 0, %18 ], [ -1, %4 ]
ret i32 %25
}