#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 pc_map {
  int dummy;
};

/* Variables and functions */
int pc_map_add(struct pc_map *, int, int);
int /*<<< orphan*/ pc_map_deinit(struct pc_map *);
int pc_map_init_empty(struct pc_map *, int);
int pc_map_init_identity(struct pc_map *map, int size) {
  int err;
  err = pc_map_init_empty(map, size);
  if (err)
    return err;
  for (int i = 0; i < size; i++) {
    err = pc_map_add(map, i, i);
    if (err) {
      pc_map_deinit(map);
      return err;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<pc_map_init_identity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <pc_map_init_empty@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1163 <pc_map_init_identity+0x33>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c0 <pc_map_init_identity+0x90>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b9 <pc_map_init_identity+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <pc_map_add@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11a6 <pc_map_init_identity+0x76>
mov    -0x10(%rbp),%rdi
call   1050 <pc_map_deinit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c0 <pc_map_init_identity+0x90>
jmp    11ab <pc_map_init_identity+0x7b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <pc_map_init_identity+0x3a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pc_map_init_identity>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
call   1040 <pc_map_init_empty@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1176 <pc_map_init_identity+0x46>
test   %r15d,%r15d
jle    1168 <pc_map_init_identity+0x38>
xor    %ebp,%ebp
nop
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
call   1030 <pc_map_add@plt>
test   %eax,%eax
jne    116c <pc_map_init_identity+0x3c>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1150 <pc_map_init_identity+0x20>
xor    %ebx,%ebx
jmp    1176 <pc_map_init_identity+0x46>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <pc_map_deinit@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pc_map = type { i32 }
define i32 @pc_map_init_identity(%struct.pc_map* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.pc_map*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.pc_map* %0, %struct.pc_map** %4
store i32 %1, i32* %5
%8 = load %struct.pc_map*, %struct.pc_map** %4
%9 = load i32, i32* %5
%10 = call i32 @pc_map_init_empty(%struct.pc_map* %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %6
store i32 %14, i32* %3
br label %36
15: ; preds = %2
store i32 0, i32* %7
br label %16
16: ; preds = %32, %15
%17 = load i32, i32* %7
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load %struct.pc_map*, %struct.pc_map** %4
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = call i32 @pc_map_add(%struct.pc_map* %21, i32 %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load %struct.pc_map*, %struct.pc_map** %4
%29 = call i32 @pc_map_deinit(%struct.pc_map* %28)
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %36
31: ; preds = %20
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %16
35: ; preds = %16
store i32 0, i32* %3
br label %36
36: ; preds = %35, %27, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.pc_map = type { i32 }
define i32 @pc_map_init_identity(%struct.pc_map* %0, i32 %1) {
%3 = tail call i32 @pc_map_init_empty(%struct.pc_map* %0, i32 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = icmp sgt i32 %1, 0
br i1 %6, label %9, label %16
7: ; preds = %9
%8 = icmp eq i32 %13, %1
br i1 %8, label %16, label %9
9: ; preds = %5, %7
%10 = phi i32 [ %13, %7 ], [ 0, %5 ]
%11 = tail call i32 @pc_map_add(%struct.pc_map* %0, i32 %10, i32 %10)
%12 = icmp eq i32 %11, 0
%13 = add nuw nsw i32 %10, 1
br i1 %12, label %7, label %14
14: ; preds = %9
%15 = tail call i32 @pc_map_deinit(%struct.pc_map* %0)
br label %16
16: ; preds = %7, %5, %14, %2
%17 = phi i32 [ %3, %2 ], [ %11, %14 ], [ 0, %5 ], [ 0, %7 ]
ret i32 %17
}