#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 replace(char ch, char *array) {
  int i;
  int len = 8;
  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):
<replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x8,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c5 <replace+0xb5>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1189 <replace+0x79>
mov    -0x30(%rbp),%rax
mov    -0x1(%rbp),%dl
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    119f <replace+0x8f>
mov    -0x30(%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    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe52(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <replace+0x46>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace>:
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
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
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 @replace(i8 signext %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8 %0, i8* %3
store i8* %1, i8** %4
store i32 8, i32* %6
%9 = load i32, i32* %6
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %7
%12 = alloca i8, i64 %10
store i64 %10, i64* %8
store i32 0, i32* %5
br label %13
13: ; preds = %41, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %44
17: ; preds = %13
%18 = load i32, i32* %5
%19 = srem i32 %18, 2
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8, i8* %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %12, i64 %24
store i8 %22, i8* %25
br label %35
26: ; preds = %17
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %12, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %26, %21
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %12, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %39)
br label %41
41: ; preds = %35
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %13
44: ; preds = %13
%45 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Array[i] is %c \0A\00"
define void @replace(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)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %0)
ret void
}