#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);
void intersperse2(char ch, char *array) {
  int j;
  int length = 8;
  int len = (length * 2) + 1;
  char res[len];
  for ((j = 0); (j < len); j++) {
    if (j == 0)
      res[j] = ch;
    else if (j % 2 == 1)
      res[j] = array[j / 2];
    else
      res[j] = ch;
    printf("Array[j] is %c \n", res[j]);
  }
}


x86 assembly (clang, -O0):
<intersperse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x8,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ff <intersperse2+0xef>
cmpl   $0x0,-0x14(%rbp)
jne    118b <intersperse2+0x7b>
mov    -0x38(%rbp),%rax
mov    -0x1(%rbp),%dl
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d9 <intersperse2+0xc9>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11c6 <intersperse2+0xb6>
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x38(%rbp),%rax
movslq %edx,%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d4 <intersperse2+0xc4>
mov    -0x38(%rbp),%rax
mov    -0x1(%rbp),%dl
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d9 <intersperse2+0xc9>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe18(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1162 <intersperse2+0x52>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intersperse2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xedd(%rip),%r15
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    $0x1,%ebx
jmp    1155 <intersperse2+0x45>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x11,%rbx
je     1167 <intersperse2+0x57>
mov    %ebp,%eax
test   $0x1,%bl
je     1140 <intersperse2+0x30>
mov    %ebx,%eax
shr    %eax
movzbl (%r14,%rax,1),%eax
jmp    1140 <intersperse2+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"Array[j] is %c \0A\00"
define void @intersperse2(i8 signext %0, i8* nocapture %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %0)
br label %4
4: ; preds = %13, %2
%5 = phi i64 [ 1, %2 ], [ %16, %13 ]
%6 = and i64 %5, 1
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = lshr i64 %5, 1
%10 = and i64 %9, 2147483647
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
br label %13
13: ; preds = %4, %8
%14 = phi i8 [ %12, %8 ], [ %0, %4 ]
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = add nuw nsw i64 %5, 1
%17 = icmp eq i64 %16, 17
br i1 %17, label %18, label %4
18: ; preds = %13
ret void
}