#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 f();
int /*<<< orphan*/ printf(char *);
void test4() {
  int count = 10;
  void *addr[count];
  do {
    int a[f()];
    addr[--count] = a;
    continue;
  } while (count);
  if (addr[9] == addr[0]) {
    printf("OK\n");
  } else {
    printf("NOT OK\n");
  }
}


x86 assembly (clang, -O0):
<test4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0xa,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    -0x4(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
cmpl   $0x0,-0x4(%rbp)
jne    1156 <test4+0x36>
mov    -0x30(%rbp),%rcx
mov    0x48(%rcx),%rax
cmp    (%rcx),%rax
jne    11c8 <test4+0xa8>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
jmp    11d4 <test4+0xb4>
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test4>:
push   %rax
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
xor    %eax,%eax
call   1040 <f@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [4 x i8] c"OK\0A\00"
@.str.1 = [8 x i8] c"NOT OK\0A\00"
define void @test4() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i32 10, i32* %1
%6 = load i32, i32* %1
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %2
%9 = alloca i8*, i64 %7
store i64 %7, i64* %3
br label %10
10: ; preds = %21, %0
%11 = call i32 (...) @f()
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i32, i64 %12
store i64 %12, i64* %5
%15 = bitcast i32* %14 to i8*
%16 = load i32, i32* %1
%17 = add nsw i32 %16, -1
store i32 %17, i32* %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %9, i64 %18
store i8* %15, i8** %19
%20 = load i8*, i8** %4
br label %21
21: ; preds = %10
%22 = load i32, i32* %1
%23 = icmp ne i32 %22, 0
br i1 %23, label %10, label %24
24: ; preds = %21
%25 = getelementptr inbounds i8*, i8** %9, i64 9
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8*, i8** %9, i64 0
%28 = load i8*, i8** %27
%29 = icmp eq i8* %26, %28
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %34
32: ; preds = %24
%33 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
@str = [7 x i8] c"NOT OK\00"
define void @test4() {
%1 = call i32 (...) @f()
%2 = call i32 (...) @f()
%3 = call i32 (...) @f()
%4 = call i32 (...) @f()
%5 = call i32 (...) @f()
%6 = call i32 (...) @f()
%7 = call i32 (...) @f()
%8 = call i32 (...) @f()
%9 = call i32 (...) @f()
%10 = call i32 (...) @f()
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
ret void
}