#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 */
struct counter *alloc_counter(int, int);
int /*<<< orphan*/ free_counter(struct counter *);
int inc_counter(struct counter *);
int /*<<< orphan*/ print_counter(struct counter *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  struct counter *c = NULL;
  int i;
  int n;
  c = alloc_counter(10, 3);
  for (i = 0; i < 1001; i++) {
    n = inc_counter(c);
    if (n == 1)
      printf("++++\n");
    print_counter(c, stdout);
  }
  free_counter(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0xa,%edi
mov    $0x3,%esi
call   1030 <alloc_counter@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e9,-0x1c(%rbp)
jge    11d7 <main+0x87>
mov    -0x18(%rbp),%rdi
call   1070 <inc_counter@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    11b7 <main+0x67>
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
call   1060 <print_counter@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <main+0x38>
mov    -0x18(%rbp),%rdi
call   1040 <free_counter@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
mov    $0x3,%esi
call   1030 <alloc_counter@plt>
mov    %rax,%rbx
mov    $0x3e9,%ebp
lea    0xe8b(%rip),%r14
mov    0x2e64(%rip),%r15
jmp    1190 <main+0x40>
xchg   %ax,%ax
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <print_counter@plt>
add    $0xffffffff,%ebp
je     11a7 <main+0x57>
mov    %rbx,%rdi
call   1070 <inc_counter@plt>
cmp    $0x1,%eax
jne    1180 <main+0x30>
mov    %r14,%rdi
call   1050 <puts@plt>
jmp    1180 <main+0x30>
mov    %rbx,%rdi
call   1040 <free_counter@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.counter = type { i32 }
@.str = [6 x i8] c"++++\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.counter*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.counter* null, %struct.counter** %6
%9 = call %struct.counter* @alloc_counter(i32 10, i32 3)
store %struct.counter* %9, %struct.counter** %6
store i32 0, i32* %7
br label %10
10: ; preds = %24, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 1001
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load %struct.counter*, %struct.counter** %6
%15 = call i32 @inc_counter(%struct.counter* %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = load %struct.counter*, %struct.counter** %6
%22 = load i32, i32* @stdout
%23 = call i32 @print_counter(%struct.counter* %21, i32 %22)
br label %24
24: ; preds = %20
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %10
27: ; preds = %10
%28 = load %struct.counter*, %struct.counter** %6
%29 = call i32 @free_counter(%struct.counter* %28)
ret i32 0
}

LLVM IR (-O2):
%struct.counter = type { i32 }
@stdout = global i32 0
@str = [5 x i8] c"++++\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.counter* @alloc_counter(i32 10, i32 3)
br label %4
4: ; preds = %2, %10
%5 = phi i32 [ 0, %2 ], [ %13, %10 ]
%6 = tail call i32 @inc_counter(%struct.counter* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = load i32, i32* @stdout
%12 = tail call i32 @print_counter(%struct.counter* %3, i32 %11)
%13 = add nuw nsw i32 %5, 1
%14 = icmp eq i32 %13, 1001
br i1 %14, label %15, label %4
15: ; preds = %10
%16 = tail call i32 @free_counter(%struct.counter* %3)
ret i32 0
}