#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 */
typedef int atomic_int;

/* Variables and functions */
int ATOMIC_VAR_INIT(int /*<<< orphan*/);
int /*<<< orphan*/ abort();
void test_ptr(atomic_int *p) {
  ++*p;
  if (*p != 2)
    abort();
  *p += 2;
  if (*p != 4)
    abort();
  (*p)++;
  if (*p != 5)
    abort();
  --*p;
  if (*p != 4)
    abort();
  (*p)--;
  if (*p != 3)
    abort();
  *p -= 2;
  if (*p != 1)
    abort();
  atomic_int j = ATOMIC_VAR_INIT(0);
  j += *p;
  if (j != 1)
    abort();
  j -= *p;
  if (j != 0)
    abort();
}


x86 assembly (clang, -O0):
<test_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x2,(%rax)
je     114b <test_ptr+0x2b>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x2,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x4,(%rax)
je     116a <test_ptr+0x4a>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x5,(%rax)
je     1189 <test_ptr+0x69>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x4,(%rax)
je     11a8 <test_ptr+0x88>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x3,(%rax)
je     11c7 <test_ptr+0xa7>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x2,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x1,(%rax)
je     11e6 <test_ptr+0xc6>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %edi,%edi
call   1040 <ATOMIC_VAR_INIT@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     120d <test_ptr+0xed>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     122c <test_ptr+0x10c>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ptr>:
push   %rbx
mov    (%rdi),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rdi)
cmp    $0x2,%ecx
jne    1148 <test_ptr+0x28>
mov    %rdi,%rbx
mov    %eax,(%rdi)
xor    %edi,%edi
call   1040 <ATOMIC_VAR_INIT@plt>
mov    (%rbx),%ecx
add    %eax,%ecx
cmp    $0x1,%ecx
jne    1148 <test_ptr+0x28>
test   %eax,%eax
jne    1148 <test_ptr+0x28>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define void @test_ptr(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = load i32, i32* %4
%6 = add nsw i32 %5, 1
store i32 %6, i32* %4
%7 = load i32*, i32** %2
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (...) @abort()
unreachable
12: ; preds = %1
%13 = load i32*, i32** %2
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 2
store i32 %15, i32* %13
%16 = load i32*, i32** %2
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 4
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %12
%22 = load i32*, i32** %2
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %22
%25 = load i32*, i32** %2
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 5
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 (...) @abort()
unreachable
30: ; preds = %21
%31 = load i32*, i32** %2
%32 = load i32, i32* %31
%33 = add nsw i32 %32, -1
store i32 %33, i32* %31
%34 = load i32*, i32** %2
%35 = load i32, i32* %34
%36 = icmp ne i32 %35, 4
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 (...) @abort()
unreachable
39: ; preds = %30
%40 = load i32*, i32** %2
%41 = load i32, i32* %40
%42 = add nsw i32 %41, -1
store i32 %42, i32* %40
%43 = load i32*, i32** %2
%44 = load i32, i32* %43
%45 = icmp ne i32 %44, 3
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %39
%49 = load i32*, i32** %2
%50 = load i32, i32* %49
%51 = sub nsw i32 %50, 2
store i32 %51, i32* %49
%52 = load i32*, i32** %2
%53 = load i32, i32* %52
%54 = icmp ne i32 %53, 1
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 (...) @abort()
unreachable
57: ; preds = %48
%58 = call i32 @ATOMIC_VAR_INIT(i32 0)
store i32 %58, i32* %3
%59 = load i32*, i32** %2
%60 = load i32, i32* %59
%61 = load i32, i32* %3
%62 = add nsw i32 %61, %60
store i32 %62, i32* %3
%63 = load i32, i32* %3
%64 = icmp ne i32 %63, 1
br i1 %64, label %65, label %67
65: ; preds = %57
%66 = call i32 (...) @abort()
unreachable
67: ; preds = %57
%68 = load i32*, i32** %2
%69 = load i32, i32* %68
%70 = load i32, i32* %3
%71 = sub nsw i32 %70, %69
store i32 %71, i32* %3
%72 = load i32, i32* %3
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %67
%75 = call i32 (...) @abort()
unreachable
76: ; preds = %67
ret void
}

LLVM IR (-O2):
define void @test_ptr(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = add nsw i32 %2, 1
store i32 %3, i32* %0
%4 = icmp eq i32 %3, 2
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (...) @abort()
unreachable
7: ; preds = %1
store i32 %2, i32* %0
%8 = tail call i32 @ATOMIC_VAR_INIT(i32 0)
%9 = load i32, i32* %0
%10 = add nsw i32 %9, %8
%11 = icmp eq i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %7
%15 = icmp eq i32 %8, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 (...) @abort()
unreachable
18: ; preds = %14
ret void
}