#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 */
char *realloc(char *, int);
int /*<<< orphan*/ sink(char *);
void warn_realloc_vla(int n1, int n2, int i) {
  char *q;
  {
    char vla[n1];
    sink(vla);
    q = realloc(vla, n2);
    sink(q);
  }
  {
    char vlb[n1 + 1];
    sink(vlb);
    q = realloc(vlb + 1, n2);
    sink(q);
  }
  {
    char vlc[n1 + 2];
    sink(vlc);
    q = realloc(&vlc[2], n2);
    sink(q);
  }
  {
    char vld[7];
    sink(vld);
    q = realloc(&vld[i], n2);
    sink(q);
  }
}


x86 assembly (clang, -O0):
<warn_realloc_vla>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
call   1030 <sink@plt>
mov    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <sink@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rsp,%rdi
mov    %rdi,-0x60(%rbp)
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
call   1030 <sink@plt>
mov    -0x68(%rbp),%rcx
mov    -0x60(%rbp),%rax
neg    %rcx
lea    0x1(%rax,%rcx,1),%rdi
mov    -0x8(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <sink@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
call   1030 <sink@plt>
mov    -0x58(%rbp),%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <sink@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
lea    -0x4f(%rbp),%rdi
call   1030 <sink@plt>
movslq -0xc(%rbp),%rax
lea    -0x4f(%rbp),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <sink@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<warn_realloc_vla>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,-0x2c(%rbp)
mov    %esi,%r15d
mov    %edi,%r12d
mov    %rsp,%r13
mov    %edi,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1030 <sink@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <realloc@plt>
mov    %rax,%rdi
call   1030 <sink@plt>
mov    %r13,%rsp
mov    %rsp,%r13
lea    0x1(%r12),%ebx
mov    %rsp,%r14
add    $0xf,%rbx
and    $0xfffffffffffffff0,%rbx
mov    %r14,%rdi
sub    %rbx,%rdi
mov    %rdi,%rsp
call   1030 <sink@plt>
neg    %rbx
lea    (%r14,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r15d,%esi
call   1040 <realloc@plt>
mov    %rax,%rdi
call   1030 <sink@plt>
mov    %r13,%rsp
mov    %rsp,%r14
add    $0x2,%r12d
mov    %rsp,%rbx
add    $0xf,%r12
and    $0xfffffffffffffff0,%r12
mov    %rbx,%rdi
sub    %r12,%rdi
mov    %rdi,%rsp
call   1030 <sink@plt>
neg    %r12
lea    (%rbx,%r12,1),%rdi
add    $0x2,%rdi
mov    %r15d,%esi
call   1040 <realloc@plt>
mov    %rax,%rdi
call   1030 <sink@plt>
mov    %r14,%rsp
lea    -0x33(%rbp),%rdi
call   1030 <sink@plt>
movslq -0x2c(%rbp),%rax
lea    (%rax,%rbp,1),%rdi
add    $0xffffffffffffffcd,%rdi
mov    %r15d,%esi
call   1040 <realloc@plt>
mov    %rax,%rdi
call   1030 <sink@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @warn_realloc_vla(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca [7 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = call i32 @sink(i8* %18)
%20 = load i32, i32* %5
%21 = call i8* @realloc(i8* %18, i32 %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = call i32 @sink(i8* %22)
%24 = load i8*, i8** %8
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %10
%29 = alloca i8, i64 %27
store i64 %27, i64* %11
%30 = call i32 @sink(i8* %29)
%31 = getelementptr inbounds i8, i8* %29, i64 1
%32 = load i32, i32* %5
%33 = call i8* @realloc(i8* %31, i32 %32)
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = call i32 @sink(i8* %34)
%36 = load i8*, i8** %10
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 2
%39 = zext i32 %38 to i64
%40 = call i8* @llvm.stacksave()
store i8* %40, i8** %12
%41 = alloca i8, i64 %39
store i64 %39, i64* %13
%42 = call i32 @sink(i8* %41)
%43 = getelementptr inbounds i8, i8* %41, i64 2
%44 = load i32, i32* %5
%45 = call i8* @realloc(i8* %43, i32 %44)
store i8* %45, i8** %7
%46 = load i8*, i8** %7
%47 = call i32 @sink(i8* %46)
%48 = load i8*, i8** %12
%49 = getelementptr inbounds [7 x i8], [7 x i8]* %14, i64 0, i64 0
%50 = call i32 @sink(i8* %49)
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [7 x i8], [7 x i8]* %14, i64 0, i64 %52
%54 = load i32, i32* %5
%55 = call i8* @realloc(i8* %53, i32 %54)
store i8* %55, i8** %7
%56 = load i8*, i8** %7
%57 = call i32 @sink(i8* %56)
ret void
}

LLVM IR (-O2):
define void @warn_realloc_vla(i32 %0, i32 %1, i32 %2) {
%4 = alloca [7 x i8]
%5 = zext i32 %0 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = call i32 @sink(i8* %7)
%9 = call i8* @realloc(i8* %7, i32 %1)
%10 = call i32 @sink(i8* %9)
%11 = add nsw i32 %0, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = call i32 @sink(i8* %14)
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = call i8* @realloc(i8* %16, i32 %1)
%18 = call i32 @sink(i8* %17)
%19 = add nsw i32 %0, 2
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
%22 = alloca i8, i64 %20
%23 = call i32 @sink(i8* %22)
%24 = getelementptr inbounds i8, i8* %22, i64 2
%25 = call i8* @realloc(i8* %24, i32 %1)
%26 = call i32 @sink(i8* %25)
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%28 = call i32 @sink(i8* %27)
%29 = sext i32 %2 to i64
%30 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 %29
%31 = call i8* @realloc(i8* %30, i32 %1)
%32 = call i32 @sink(i8* %31)
ret void
}