#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);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
char *insertbegin(char *tmp, char *a) {
  char *new = (char *)malloc(sizeof(char) * (strlen(tmp) + strlen(a)));
  if (NULL == new)
    return NULL;
  int i, cnt = 0;
  for (i = 0; i < strlen(tmp); i++) {
    new[i] = tmp[i];
  }
  for (i = 0; i < strlen(a) - 1; i++) {
    new[i + strlen(tmp)] = a[i];
  }
  printf("string is %s \n", new);
  return new;
}


x86 assembly (clang, -O0):
<insertbegin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1186 <insertbegin+0x56>
movq   $0x0,-0x8(%rbp)
jmp    1259 <insertbegin+0x129>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    11d4 <insertbegin+0xa4>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <insertbegin+0x64>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1241 <insertbegin+0x111>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x41(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%ecx
mov    -0x41(%rbp),%dl
mov    %eax,%esi
mov    -0x40(%rbp),%rax
add    %esi,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11db <insertbegin+0xab>
mov    -0x20(%rbp),%rsi
lea    0xdb4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertbegin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11dc <insertbegin+0xac>
mov    %rax,%r15
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    118c <insertbegin+0x5c>
xor    %ebp,%ebp
movzbl (%r12,%rbp,1),%eax
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1170 <insertbegin+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     11cb <insertbegin+0x9b>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbp,1),%ebx
mov    %r12,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cltq
mov    %bl,(%r15,%rax,1)
add    $0x1,%rbp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jl     11a0 <insertbegin+0x70>
lea    0xe2e(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
jmp    11df <insertbegin+0xaf>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"string is %s \0A\00"
define i8* @insertbegin(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %40, label %9
9: ; preds = %2
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %15, %9
%13 = tail call i32 @strlen(i8* %1)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %24, label %38
15: ; preds = %9, %15
%16 = phi i64 [ %20, %15 ], [ 0, %9 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %7, i64 %16
store i8 %18, i8* %19
%20 = add nuw nsw i64 %16, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %15, label %12
24: ; preds = %12, %24
%25 = phi i64 [ %33, %24 ], [ 0, %12 ]
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = load i8, i8* %26
%28 = tail call i32 @strlen(i8* %0)
%29 = trunc i64 %25 to i32
%30 = add nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %7, i64 %31
store i8 %27, i8* %32
%33 = add nuw nsw i64 %25, 1
%34 = tail call i32 @strlen(i8* %1)
%35 = add nsw i32 %34, -1
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %33, %36
br i1 %37, label %24, label %38
38: ; preds = %24, %12
%39 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %40
40: ; preds = %2, %38
%41 = phi i8* [ %7, %38 ], [ null, %2 ]
ret i8* %41
}