#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*/ cha_ins(char *, char);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char str[] = "I have 6 iPhones";
  char *p = &str[0];
  int index = 0;
  while (*p) {
    p++;
    index++;
    if (index == 7)
      cha_ins(p, '9');
  }
  printf("%s", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec5(%rip),%al
mov    %al,-0x10(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     119c <main+0x7c>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x7,-0x2c(%rbp)
jne    1197 <main+0x77>
mov    -0x28(%rbp),%rdi
mov    $0x39,%esi
call   1040 <cha_ins@plt>
jmp    115d <main+0x3d>
lea    -0x20(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movaps 0xed5(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x7(%rsp),%rdi
mov    $0x39,%esi
call   1040 <cha_ins@plt>
lea    0xec7(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.str = [17 x i8] c"I have 6 iPhones\00"
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [17 x i8]* %2 to i8*
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
store i8* %6, i8** %3
store i32 0, i32* %4
br label %7
7: ; preds = %21, %0
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 7
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = call i32 @cha_ins(i8* %19, i8 signext 57)
br label %21
21: ; preds = %18, %11
br label %7
22: ; preds = %7
%23 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %23)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [17 x i8] c"I have 6 iPhones\00"
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [17 x i8]
%2 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 7
%4 = call i32 @cha_ins(i8* %3, i8 signext 57)
%5 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
ret i32 0
}