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


x86 assembly (clang, -O0):
<intersperse1>:
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),%eax
add    $0xffffffff,%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    11ce <intersperse1+0xbe>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1192 <intersperse1+0x82>
mov    -0x38(%rbp),%rax
mov    -0x1(%rbp),%dl
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11a8 <intersperse1+0x98>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe49(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115f <intersperse1+0x4f>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intersperse1>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
movsbl (%rsi),%esi
lea    0xedd(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
movsbl 0x2(%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
movsbl 0x4(%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
movsbl 0x6(%rbx),%esi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Array[i] is %c \0A\00"
define void @intersperse1(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 = sub nsw i32 %10, 1
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
store i32 0, i32* %5
br label %16
16: ; preds = %44, %2
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load i32, i32* %5
%22 = srem i32 %21, 2
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8, i8* %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %15, i64 %27
store i8 %25, i8* %28
br label %38
29: ; preds = %20
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %15, i64 %36
store i8 %34, i8* %37
br label %38
38: ; preds = %29, %24
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %15, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %42)
br label %44
44: ; preds = %38
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %16
47: ; preds = %16
%48 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Array[i] is %c \0A\00"
define void @intersperse1(i8 signext %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %3)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%6 = getelementptr inbounds i8, i8* %1, i64 2
%7 = load i8, i8* %6
%8 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%10 = getelementptr inbounds i8, i8* %1, i64 4
%11 = load i8, i8* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%14 = getelementptr inbounds i8, i8* %1, i64 6
%15 = load i8, i8* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %15)
ret void
}