#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 */
typedef size_t uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, size_t, size_t, size_t);
uint32_t array_modify(uint32_t length, uint32_t *array, uint32_t val) {
  uint32_t i = 0;
  for (i = 0; i < length; i++) {
    printf("befor C.array_modify(%d): %d -> %d\n", length, i, array[i]);
  }
  for (i = 0; i < length; i++) {
    array[i] = val;
    printf("after C.array_modify(%d): %d -> %d\n", length, i, array[i]);
  }
  return length;
}


x86 assembly (clang, -O0):
<array_modify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1173 <array_modify+0x63>
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1134 <array_modify+0x24>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11ca <array_modify+0xba>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117b <array_modify+0x6b>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_modify>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
test   %rdi,%rdi
je     117e <array_modify+0x6e>
mov    %rdx,%r14
mov    %rsi,%r15
xor    %ebx,%ebx
lea    0xed0(%rip),%r13
mov    (%r15,%rbx,8),%rcx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <array_modify+0x20>
test   %r12,%r12
je     117e <array_modify+0x6e>
xor    %ebx,%ebx
lea    0xecb(%rip),%r13
nopl   0x0(%rax)
mov    %r14,(%r15,%rbx,8)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <array_modify+0x50>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"befor C.array_modify(%d): %d -> %d\0A\00"
@.str.1 = [36 x i8] c"after C.array_modify(%d): %d -> %d\0A\00"
define i64 @array_modify(i64 %0, i64* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i64* %1, i64** %5
store i64 %2, i64* %6
store i64 0, i64* %7
store i64 0, i64* %7
br label %8
8: ; preds = %20, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i64, i64* %4
%14 = load i64, i64* %7
%15 = load i64*, i64** %5
%16 = load i64, i64* %7
%17 = getelementptr inbounds i64, i64* %15, i64 %16
%18 = load i64, i64* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i64 %13, i64 %14, i64 %18)
br label %20
20: ; preds = %12
%21 = load i64, i64* %7
%22 = add i64 %21, 1
store i64 %22, i64* %7
br label %8
23: ; preds = %8
store i64 0, i64* %7
br label %24
24: ; preds = %40, %23
%25 = load i64, i64* %7
%26 = load i64, i64* %4
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %43
28: ; preds = %24
%29 = load i64, i64* %6
%30 = load i64*, i64** %5
%31 = load i64, i64* %7
%32 = getelementptr inbounds i64, i64* %30, i64 %31
store i64 %29, i64* %32
%33 = load i64, i64* %4
%34 = load i64, i64* %7
%35 = load i64*, i64** %5
%36 = load i64, i64* %7
%37 = getelementptr inbounds i64, i64* %35, i64 %36
%38 = load i64, i64* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %33, i64 %34, i64 %38)
br label %40
40: ; preds = %28
%41 = load i64, i64* %7
%42 = add i64 %41, 1
store i64 %42, i64* %7
br label %24
43: ; preds = %24
%44 = load i64, i64* %4
ret i64 %44
}

LLVM IR (-O2):
@.str = [36 x i8] c"befor C.array_modify(%d): %d -> %d\0A\00"
@.str.1 = [36 x i8] c"after C.array_modify(%d): %d -> %d\0A\00"
define i64 @array_modify(i64 returned %0, i64* nocapture %1, i64 %2) {
%4 = icmp eq i64 %0, 0
br i1 %4, label %19, label %6
5: ; preds = %6
br i1 %4, label %19, label %13
6: ; preds = %3, %6
%7 = phi i64 [ %11, %6 ], [ 0, %3 ]
%8 = getelementptr inbounds i64, i64* %1, i64 %7
%9 = load i64, i64* %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %7, i64 %9)
%11 = add nuw i64 %7, 1
%12 = icmp eq i64 %11, %0
br i1 %12, label %5, label %6
13: ; preds = %5, %13
%14 = phi i64 [ %17, %13 ], [ 0, %5 ]
%15 = getelementptr inbounds i64, i64* %1, i64 %14
store i64 %2, i64* %15
%16 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %0, i64 %14, i64 %2)
%17 = add nuw i64 %14, 1
%18 = icmp eq i64 %17, %0
br i1 %18, label %19, label %13
19: ; preds = %13, %3, %5
ret i64 %0
}