#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 */
typedef int /*<<< orphan*/ suffix;

/* Variables and functions */
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char const *mktemp(char *);
size_t strlen(char const *);
const char *_amkrtemp(const char *path) {
  size_t len = strlen(path);
  const char suffix[] = ".amkrtempXXXXXX";
  char *template = malloc(len + sizeof(suffix));
  memcpy(template, path, len);
  memcpy(template + len, suffix, sizeof(suffix));
  return mktemp(template);
}


x86 assembly (clang, -O0):
<_amkrtemp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
add    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1060 <mktemp@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_amkrtemp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
movaps 0xea5(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
add    %r15,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    %r15,%rdi
call   1060 <mktemp@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const._amkrtemp.suffix = [16 x i8] c".amkrtempXXXXXX\00"
define i8* @_amkrtemp(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [16 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
%8 = bitcast [16 x i8]* %4 to i8*
%9 = load i64, i64* %3
%10 = add i64 %9, 16
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = load i8*, i8** %2
%14 = load i64, i64* %3
%15 = trunc i64 %14 to i32
%16 = call i32 @memcpy(i8* %12, i8* %13, i32 %15)
%17 = load i8*, i8** %5
%18 = load i64, i64* %3
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%21 = call i32 @memcpy(i8* %19, i8* %20, i32 16)
%22 = load i8*, i8** %5
%23 = call i8* @mktemp(i8* %22)
ret i8* %23
}

LLVM IR (-O2):
@__const._amkrtemp.suffix = [16 x i8] c".amkrtempXXXXXX\00"
define i8* @_amkrtemp(i8* %0) {
%2 = alloca [16 x i8]
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = add i64 %3, 16
%6 = tail call i8* @malloc(i64 %5)
%7 = trunc i64 %3 to i32
%8 = tail call i32 @memcpy(i8* %6, i8* %0, i32 %7)
%9 = getelementptr inbounds i8, i8* %6, i64 %3
%10 = call i32 @memcpy(i8* %9, i8* %4, i32 16)
%11 = call i8* @mktemp(i8* %6)
ret i8* %11
}