#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*/ __builtin_brev_ldw(int *, int *, int);
int add(int);
int brev_store_elimination_test3(int *ptr, int mod, int inc) {
  int dst = 100;
  for (int i = 0; i < inc; ++i) {
    __builtin_brev_ldw(ptr, &dst, mod);
    dst = add(dst);
  }
  return dst;
}


x86 assembly (clang, -O0):
<brev_store_elimination_test3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1175 <brev_store_elimination_test3+0x55>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    -0x14(%rbp),%rsi
call   1040 <__builtin_brev_ldw@plt>
mov    -0x14(%rbp),%edi
call   1030 <add@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1140 <brev_store_elimination_test3+0x20>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brev_store_elimination_test3>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x64,0x4(%rsp)
test   %edx,%edx
jle    1162 <brev_store_elimination_test3+0x42>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0x4(%rsp),%r15
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <__builtin_brev_ldw@plt>
mov    0x4(%rsp),%edi
call   1030 <add@plt>
mov    %eax,0x4(%rsp)
add    $0xffffffff,%ebx
jne    1140 <brev_store_elimination_test3+0x20>
jmp    1167 <brev_store_elimination_test3+0x47>
mov    $0x64,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @brev_store_elimination_test3(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 100, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %19, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = load i32, i32* %5
%16 = call i32 @__builtin_brev_ldw(i32* %14, i32* %7, i32 %15)
%17 = load i32, i32* %7
%18 = call i32 @add(i32 %17)
store i32 %18, i32* %7
br label %19
19: ; preds = %13
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
store i32 %21, i32* %8
br label %9
22: ; preds = %9
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
define i32 @brev_store_elimination_test3(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 100, i32* %4
%6 = icmp sgt i32 %2, 0
br i1 %6, label %9, label %7
7: ; preds = %9, %3
%8 = phi i32 [ 100, %3 ], [ %13, %9 ]
ret i32 %8
9: ; preds = %3, %9
%10 = phi i32 [ %14, %9 ], [ 0, %3 ]
%11 = call i32 @__builtin_brev_ldw(i32* %0, i32* %4, i32 %1)
%12 = load i32, i32* %4
%13 = call i32 @add(i32 %12)
store i32 %13, i32* %4
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, %2
br i1 %15, label %7, label %9
}