#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 */
scalar_t__ malloc(int);
char *create_string(char *head, char *end) {
  char a = *end;
  *end = '\0';
  char *b = (char *)malloc(64), *aa = b;
  while (*head != '\0') {
    *b++ = *head++;
  }
  *b++ = a;
  *b = '\0';
  return aa;
}


x86 assembly (clang, -O0):
<create_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x40,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117d <create_string+0x6d>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1146 <create_string+0x36>
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_string>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rsi),%bpl
movb   $0x0,(%rsi)
mov    $0x40,%edi
call   1030 <malloc@plt>
mov    (%rbx),%cl
test   %cl,%cl
je     1153 <create_string+0x43>
add    $0x1,%rbx
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %cl,(%rdx)
add    $0x1,%rdx
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1140 <create_string+0x30>
jmp    1156 <create_string+0x46>
mov    %rax,%rdx
mov    %bpl,(%rdx)
movb   $0x0,0x1(%rdx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @create_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
store i8 %9, i8* %5
%10 = load i8*, i8** %4
store i8 0, i8* %10
%11 = call i64 @malloc(i32 64)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
br label %14
14: ; preds = %19, %2
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
%22 = load i8, i8* %20
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
store i8 %22, i8* %23
br label %14
25: ; preds = %14
%26 = load i8, i8* %5
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
store i8 %26, i8* %27
%29 = load i8*, i8** %6
store i8 0, i8* %29
%30 = load i8*, i8** %7
ret i8* %30
}

LLVM IR (-O2):
define i8* @create_string(i8* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
store i8 0, i8* %1
%4 = tail call i64 @malloc(i32 64)
%5 = inttoptr i64 %4 to i8*
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %14, %8 ], [ %6, %2 ]
%10 = phi i8* [ %12, %8 ], [ %0, %2 ]
%11 = phi i8* [ %13, %8 ], [ %5, %2 ]
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %9, i8* %11
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %2
%17 = phi i8* [ %5, %2 ], [ %13, %8 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %3, i8* %17
store i8 0, i8* %18
ret i8* %5
}