#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, int);
int foo(int n, int a[][n]) {
  while (n--) {
    printf("(*a)[%d] = %d\n", n, a[0][n]);
  }
  return sizeof(*a);
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     1168 <foo+0x58>
mov    -0x18(%rbp),%rcx
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rax
imul   $0x0,%rcx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
jmp    1126 <foo+0x16>
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
test   %edi,%edi
je     1155 <foo+0x45>
movslq %r14d,%rax
lea    (%rsi,%rax,4),%rbx
add    $0xfffffffffffffffc,%rbx
lea    -0x1(%r14),%ebp
lea    0xecc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0xfffffffffffffffc,%rbx
add    $0xffffffff,%ebp
jb     1140 <foo+0x30>
shl    $0x2,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"(*a)[%d] = %d\0A\00"
define i32 @foo(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%5 = load i32, i32* %3
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %11, %2
%8 = load i32, i32* %3
%9 = add nsw i32 %8, -1
store i32 %9, i32* %3
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %3
%13 = load i32*, i32** %4
%14 = mul nsw i64 0, %6
%15 = getelementptr inbounds i32, i32* %13, i64 %14
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %19)
br label %7
21: ; preds = %7
%22 = load i32*, i32** %4
%23 = mul nuw i64 4, %6
%24 = trunc i64 %23 to i32
ret i32 %24
}

LLVM IR (-O2):
@.str = [15 x i8] c"(*a)[%d] = %d\0A\00"
define i32 @foo(i32 %0, i32* nocapture %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = sext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ %5, %4 ], [ %8, %6 ]
%8 = add nsw i64 %7, -1
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = load i32, i32* %9
%11 = trunc i64 %8 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %10)
%13 = icmp eq i32 %11, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %2
%15 = shl i32 %0, 2
ret i32 %15
}