#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ stderr;
void finalize_value(int *p) {
  static long counter = 0;
  counter += 1;
  if (counter % 1000000 == 0) {
    fprintf(stderr, "finalize_value: %ld calls\n", counter);
  }
  if (*p != 0x11223344) {
    fprintf(stderr, "finalize_value: %x != %x after %ld calls\n", *p,
            0x11223344, counter);
    abort();
  }
}


x86 assembly (clang, -O0):
<finalize_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2f05(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2efa(%rip)
mov    0x2ef3(%rip),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1179 <finalize_value+0x59>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    0x2ecf(%rip),%rax
mov    %eax,%edx
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
cmpl   $0x11223344,(%rax)
je     11b9 <finalize_value+0x99>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    0x2e99(%rip),%r8
lea    0xe75(%rip),%rsi
mov    $0x11223344,%ecx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finalize_value>:
push   %rbx
mov    %rdi,%rbx
mov    0x2f0d(%rip),%rdx
add    $0x1,%rdx
mov    %rdx,0x2f02(%rip)
movabs $0x790fb65668c26139,%rax
b6 0f 79
imul   %rdx,%rax
movabs $0x218def416bd80,%rcx
add    %rax,%rcx
ror    $0x6,%rcx
movabs $0x10c6f7a0b5ec,%rax
cmp    %rax,%rcx
ja     117b <finalize_value+0x5b>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edx
cmp    $0x11223344,%edx
jne    1187 <finalize_value+0x67>
pop    %rbx
ret
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2ea1(%rip),%r8
lea    0xe7d(%rip),%rsi
mov    $0x11223344,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@finalize_value.counter = internal global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"finalize_value: %ld calls\0A\00"
@.str.1 = [42 x i8] c"finalize_value: %x != %x after %ld calls\0A\00"
define void @finalize_value(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i64, i64* @finalize_value.counter
%4 = add nsw i64 %3, 1
store i64 %4, i64* @finalize_value.counter
%5 = load i64, i64* @finalize_value.counter
%6 = srem i64 %5, 1000000
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i64, i64* @finalize_value.counter
%11 = trunc i64 %10 to i32
%12 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %8, %1
%14 = load i32*, i32** %2
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, 287454020
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i32*, i32** %2
%20 = load i32, i32* %19
%21 = load i64, i64* @finalize_value.counter
%22 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 287454020, i64 %21)
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %13
ret void
}

LLVM IR (-O2):
@finalize_value.counter = internal unnamed_addr global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"finalize_value: %ld calls\0A\00"
@.str.1 = [42 x i8] c"finalize_value: %x != %x after %ld calls\0A\00"
define void @finalize_value(i32* nocapture %0) {
%2 = load i64, i64* @finalize_value.counter
%3 = add nsw i64 %2, 1
store i64 %3, i64* @finalize_value.counter
%4 = srem i64 %3, 1000000
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = trunc i64 %3 to i32
%9 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %6, %1
%11 = load i32, i32* %0
%12 = icmp eq i32 %11, 287454020
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i64, i64* @finalize_value.counter
%16 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 287454020, i64 %15)
%17 = tail call i32 (...) @abort()
unreachable
18: ; preds = %10
ret void
}