#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 */
struct counter {
  int dummy;
};

/* Variables and functions */
int counter_get(struct counter *);
struct counter *create_counter();
int /*<<< orphan*/ dispose(struct counter *);
int /*<<< orphan*/ inc(struct counter *);
int /*<<< orphan*/ swap(struct counter *, struct counter *);
int main() {
  struct counter *c1 = create_counter();
  inc(c1);
  struct counter *c2 = create_counter();
  inc(c2);
  inc(c2);
  swap(c1, c2);
  int tmp = counter_get(c1);
  dispose(c1);
  dispose(c2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <create_counter@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <inc@plt>
mov    $0x0,%al
call   1040 <create_counter@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <inc@plt>
mov    -0x18(%rbp),%rdi
call   1070 <inc@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <swap@plt>
mov    -0x10(%rbp),%rdi
call   1050 <counter_get@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <dispose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <dispose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <create_counter@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <inc@plt>
xor    %eax,%eax
call   1040 <create_counter@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <inc@plt>
mov    %rbx,%rdi
call   1070 <inc@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <swap@plt>
mov    %r14,%rdi
call   1050 <counter_get@plt>
mov    %r14,%rdi
call   1030 <dispose@plt>
mov    %rbx,%rdi
call   1030 <dispose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.counter = type { i32 }
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.counter*
%3 = alloca %struct.counter*
%4 = alloca i32
store i32 0, i32* %1
%5 = call %struct.counter* (...) @create_counter()
store %struct.counter* %5, %struct.counter** %2
%6 = load %struct.counter*, %struct.counter** %2
%7 = call i32 @inc(%struct.counter* %6)
%8 = call %struct.counter* (...) @create_counter()
store %struct.counter* %8, %struct.counter** %3
%9 = load %struct.counter*, %struct.counter** %3
%10 = call i32 @inc(%struct.counter* %9)
%11 = load %struct.counter*, %struct.counter** %3
%12 = call i32 @inc(%struct.counter* %11)
%13 = load %struct.counter*, %struct.counter** %2
%14 = load %struct.counter*, %struct.counter** %3
%15 = call i32 @swap(%struct.counter* %13, %struct.counter* %14)
%16 = load %struct.counter*, %struct.counter** %2
%17 = call i32 @counter_get(%struct.counter* %16)
store i32 %17, i32* %4
%18 = load %struct.counter*, %struct.counter** %2
%19 = call i32 @dispose(%struct.counter* %18)
%20 = load %struct.counter*, %struct.counter** %3
%21 = call i32 @dispose(%struct.counter* %20)
ret i32 0
}

LLVM IR (-O2):
%struct.counter = type { i32 }
define i32 @main() {
%1 = tail call %struct.counter* (...) @create_counter()
%2 = tail call i32 @inc(%struct.counter* %1)
%3 = tail call %struct.counter* (...) @create_counter()
%4 = tail call i32 @inc(%struct.counter* %3)
%5 = tail call i32 @inc(%struct.counter* %3)
%6 = tail call i32 @swap(%struct.counter* %1, %struct.counter* %3)
%7 = tail call i32 @counter_get(%struct.counter* %1)
%8 = tail call i32 @dispose(%struct.counter* %1)
%9 = tail call i32 @dispose(%struct.counter* %3)
ret i32 0
}