#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 *, int);
void write_memory(int *buffer, int *begin, int *end) {
  int i;
  for (i = 0; i < 10; i++) {
    while ((*begin + 1) % 5 == *end)
      ;
    buffer[*begin] = i * i;
    *begin = (*begin + 1) % 5;
    printf("Parent: initial value %2d before writing in the buffer\n", i);
  }
}


x86 assembly (clang, -O0):
<write_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11a5 <write_memory+0x95>
jmp    113a <write_memory+0x2a>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
cmp    (%rax),%edx
jne    115c <write_memory+0x4c>
jmp    113a <write_memory+0x2a>
mov    -0x1c(%rbp),%edx
imul   -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    %edx,(%rax)
mov    -0x1c(%rbp),%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <write_memory+0x1b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_memory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %ebp,%ebp
lea    0xed6(%rip),%r12
nopw   0x0(%rax,%rax,1)
movslq (%rbx),%rax
lea    0x1(%rax),%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x21,%rdx
add    %esi,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
cmp    (%r14),%ecx
je     11b0 <write_memory+0xa0>
mov    %ebp,%ecx
imul   %ebp,%ecx
mov    %ecx,(%r15,%rax,4)
mov    (%rbx),%eax
mov    %eax,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%rbx)
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
jne    1130 <write_memory+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nop
jmp    11b0 <write_memory+0xa0>

LLVM IR (-O0):
@.str = [56 x i8] c"Parent: initial value %2d before writing in the buffer\0A\00"
define void @write_memory(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %37, %3
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %40
11: ; preds = %8
br label %12
12: ; preds = %20, %11
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = srem i32 %15, 5
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %12
br label %12
21: ; preds = %12
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = mul nsw i32 %22, %23
%25 = load i32*, i32** %4
%26 = load i32*, i32** %5
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
store i32 %24, i32* %29
%30 = load i32*, i32** %5
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1
%33 = srem i32 %32, 5
%34 = load i32*, i32** %5
store i32 %33, i32* %34
%35 = load i32, i32* %7
%36 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %21
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %8
40: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [56 x i8] c"Parent: initial value %2d before writing in the buffer\0A\00"
define void @write_memory(i32* nocapture writeonly %0, i32* nocapture %1, i32* nocapture %2) {
br label %4
4: ; preds = %3, %12
%5 = phi i32 [ 0, %3 ], [ %20, %12 ]
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
%8 = srem i32 %7, 5
%9 = load i32, i32* %2
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %4, %11
br label %11
12: ; preds = %4
%13 = mul nsw i32 %5, %5
%14 = sext i32 %6 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
store i32 %13, i32* %15
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
%18 = srem i32 %17, 5
store i32 %18, i32* %1
%19 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %5)
%20 = add nuw nsw i32 %5, 1
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %4
22: ; preds = %12
ret void
}