#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 */
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
void insert(char str[]) {
  int i;
  for (i = strlen(str); i > 0; i--) {
    str[2 * i] = str[i];
    str[2 * i - 1] = ' ';
  }
  printf("output:\n%s\n", str);
}


x86 assembly (clang, -O0):
<insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    117f <insert+0x5f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <insert+0x18>
mov    -0x8(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1199 <insert+0x79>
mov    %eax,%ecx
test   $0x1,%cl
je     1146 <insert+0x26>
mov    (%rbx,%rcx,1),%dl
movslq %eax,%rsi
mov    %dl,(%rbx,%rsi,2)
movb   $0x20,-0x1(%rbx,%rsi,2)
add    $0xffffffffffffffff,%rcx
cmp    $0x1,%eax
je     1199 <insert+0x79>
lea    (%rcx,%rcx,1),%eax
add    $0x1,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x1(%rbx,%rcx,1),%edx
cltq
mov    %dl,(%rbx,%rax,1)
lea    -0x1(%rax),%edx
movslq %edx,%rdx
movb   $0x20,(%rbx,%rdx,1)
movzbl -0x2(%rbx,%rcx,1),%edx
lea    -0x2(%rax),%esi
movslq %esi,%rsi
mov    %dl,(%rbx,%rsi,1)
lea    -0x3(%rax),%edx
movslq %edx,%rdx
movb   $0x20,(%rbx,%rdx,1)
add    $0xfffffffc,%eax
add    $0xfffffffffffffffe,%rcx
cmp    $0x1,%rcx
ja     1160 <insert+0x40>
lea    0xe60(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"output:\0A%s\0A\00"
define void @insert(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
store i32 %5, i32* %3
br label %6
6: ; preds = %26, %1
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = mul nsw i32 2, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 %14, i8* %19
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = mul nsw i32 2, %21
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
store i8 32, i8* %25
br label %26
26: ; preds = %9
%27 = load i32, i32* %3
%28 = add nsw i32 %27, -1
store i32 %28, i32* %3
br label %6
29: ; preds = %6
%30 = load i8*, i8** %2
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %30)
ret void
}

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