#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 person {
  int dummy;
};
struct arraylist {
  int dummy;
};

/* Variables and functions */
struct arraylist *create_arraylist();
struct person *create_person();
int /*<<< orphan*/ die(struct person *);
int /*<<< orphan*/ divorce(struct person *);
int /*<<< orphan*/ list_add(struct arraylist *, struct person *);
int /*<<< orphan*/ list_dispose(struct arraylist *);
struct person *list_get(struct arraylist *, int);
int list_length(struct arraylist *);
int /*<<< orphan*/ list_remove_nth(struct arraylist *, int);
int /*<<< orphan*/ marry(struct person *, struct person *);
struct person *person_get_spouse(struct person *);
int /*<<< orphan*/ puts(char *);
int read_int();
int main() {
  struct arraylist *persons = create_arraylist();
  puts("Welcome to the Municipal Registry\n");
  while (true) {
    int choice = 0;
    puts("Menu:\n");
    puts("  1. Register birth.\n");
    puts("  2. Register marriage.\n");
    puts("  3. Register divorce.\n");
    puts("  4. Register death.\n");
    puts("  5. Exit.\n");
    choice = read_int();
    if (choice == 1) {
      struct person *p = create_person();
      list_add(persons, p);
    } else if (choice == 2) {
      int index1 = 0;
      int index2 = 0;
      int max = 0;
      struct person *p1 = 0;
      struct person *p2 = 0;
      struct person *spouse1 = 0;
      struct person *spouse2 = 0;
      puts("Enter the index of the first person.\n");
      index1 = read_int();
      puts("Enter the index of the second person.\n");
      index2 = read_int();
      max = list_length(persons);
      if (0 <= index1 && index1 < max && 0 <= index2 && index2 < max &&
          index1 != index2) {
        p1 = list_get(persons, index1);
        p2 = list_get(persons, index2);
        spouse1 = person_get_spouse(p1);
        spouse2 = person_get_spouse(p2);
        if (spouse1 == 0 && spouse2 == 0) {
          marry(p1, p2);
        } else {
          puts("One of the persons is already married.");
        }
      } else {
        puts("Index out of bounds or same index.");
      }
    } else if (choice == 3) {
      int index = 0;
      int max = 0;
      struct person *p = 0;
      struct person *spouse = 0;
      puts("Enter the husband's index.");
      index = read_int();
      max = list_length(persons);
      if (0 <= index && index < max) {
        p = list_get(persons, index);
        spouse = person_get_spouse(p);
        if (spouse != 0) {
          divorce(p);
        } else {
          puts("The person is not married.");
        }
      } else {
        puts("Invalid index");
      }
    } else if (choice == 4) {
      int index = 0;
      int max = 0;
      struct person *p = 0;
      struct person *spouse = 0;
      puts("Enter a person's index.");
      index = read_int();
      max = list_length(persons);
      if (0 <= index && index < max) {
        p = list_get(persons, index);
        list_remove_nth(persons, index);
        spouse = person_get_spouse(p);
        if (spouse != 0) {
        }
        die(p);
        if (spouse != 0) {
        }
      } else {
        puts("Invalid index.");
      }
    } else if (choice == 5) {
      int i = list_length(persons);
      while (i != 0) {
        struct person *p = list_get(persons, 0);
        struct person *spouse = 0;
        list_remove_nth(persons, 0);
        spouse = person_get_spouse(p);
        die(p);
        i = list_length(persons);
      }
      list_dispose(persons);
      return 0;
    } else {
      puts("Invalid Choice");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <create_arraylist@plt>
mov    %rax,-0x10(%rbp)
lea    0xe0c(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x14(%rbp)
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe44(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   10a0 <read_int@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1279 <main+0xa9>
mov    $0x0,%al
call   10f0 <create_person@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10c0 <list_add@plt>
jmp    15e5 <main+0x415>
cmpl   $0x2,-0x14(%rbp)
jne    13ae <main+0x1de>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   10a0 <read_int@plt>
mov    %eax,-0x24(%rbp)
lea    0xde4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   10a0 <read_int@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   10e0 <list_length@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jg     139d <main+0x1cd>
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    139d <main+0x1cd>
xor    %eax,%eax
cmp    -0x28(%rbp),%eax
jg     139d <main+0x1cd>
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    139d <main+0x1cd>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     139d <main+0x1cd>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <list_get@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1050 <list_get@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <person_get_spouse@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <person_get_spouse@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    138c <main+0x1bc>
cmpq   $0x0,-0x50(%rbp)
jne    138c <main+0x1bc>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1090 <marry@plt>
jmp    1398 <main+0x1c8>
lea    0xd4d(%rip),%rdi
call   1040 <puts@plt>
jmp    13a9 <main+0x1d9>
lea    0xd63(%rip),%rdi
call   1040 <puts@plt>
jmp    15e0 <main+0x410>
cmpl   $0x3,-0x14(%rbp)
jne    1467 <main+0x297>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
lea    0xd4d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   10a0 <read_int@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   10e0 <list_length@plt>
mov    %eax,-0x58(%rbp)
xor    %eax,%eax
cmp    -0x54(%rbp),%eax
jg     1456 <main+0x286>
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1456 <main+0x286>
mov    -0x10(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1050 <list_get@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
call   1070 <person_get_spouse@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1445 <main+0x275>
mov    -0x60(%rbp),%rdi
call   1080 <divorce@plt>
jmp    1451 <main+0x281>
lea    0xcf9(%rip),%rdi
call   1040 <puts@plt>
jmp    1462 <main+0x292>
lea    0xd03(%rip),%rdi
call   1040 <puts@plt>
jmp    15db <main+0x40b>
cmpl   $0x4,-0x14(%rbp)
jne    1530 <main+0x360>
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
lea    0xcd8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   10a0 <read_int@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rdi
call   10e0 <list_length@plt>
mov    %eax,-0x70(%rbp)
xor    %eax,%eax
cmp    -0x6c(%rbp),%eax
jg     151f <main+0x34f>
mov    -0x6c(%rbp),%eax
cmp    -0x70(%rbp),%eax
jge    151f <main+0x34f>
mov    -0x10(%rbp),%rdi
mov    -0x6c(%rbp),%esi
call   1050 <list_get@plt>
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x6c(%rbp),%esi
call   10b0 <list_remove_nth@plt>
mov    -0x78(%rbp),%rdi
call   1070 <person_get_spouse@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     1501 <main+0x331>
jmp    1501 <main+0x331>
mov    -0x78(%rbp),%rdi
call   10d0 <die@plt>
cmpq   $0x0,-0x80(%rbp)
je     151a <main+0x34a>
jmp    151a <main+0x34a>
jmp    152b <main+0x35b>
lea    0xc60(%rip),%rdi
call   1040 <puts@plt>
jmp    15d6 <main+0x406>
cmpl   $0x5,-0x14(%rbp)
jne    15c5 <main+0x3f5>
mov    -0x10(%rbp),%rdi
call   10e0 <list_length@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     15b1 <main+0x3e1>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <list_get@plt>
mov    %rax,-0x90(%rbp)
movq   $0x0,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   10b0 <list_remove_nth@plt>
mov    -0x90(%rbp),%rdi
call   1070 <person_get_spouse@plt>
mov    %rax,-0x98(%rbp)
mov    -0x90(%rbp),%rdi
call   10d0 <die@plt>
mov    -0x10(%rbp),%rdi
call   10e0 <list_length@plt>
mov    %eax,-0x84(%rbp)
jmp    1549 <main+0x379>
mov    -0x10(%rbp),%rdi
call   1030 <list_dispose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret
lea    0xbc9(%rip),%rdi
call   1040 <puts@plt>
jmp    15d6 <main+0x406>
jmp    15db <main+0x40b>
jmp    15e0 <main+0x410>
jmp    15e5 <main+0x415>
jmp    11f9 <main+0x29>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <create_arraylist@plt>
mov    %rax,%r13
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
lea    0xe46(%rip),%r12
jmp    120e <main+0x3e>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <marry@plt>
mov    %r14,%r12
lea    0xe3f(%rip),%r14
lea    0xe51(%rip),%rbx
lea    0xe62(%rip),%r15
jmp    123c <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xf63(%rip),%rdi
call   1040 <puts@plt>
lea    0xe58(%rip),%rbp
lea    0xded(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <read_int@plt>
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     12aa <main+0xda>
lea    0xd73(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   10f0 <create_person@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   10c0 <list_add@plt>
jmp    1243 <main+0x73>
lea    0xef8(%rip),%rdi
call   1040 <puts@plt>
jmp    1243 <main+0x73>
mov    %r12,%r14
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <read_int@plt>
mov    %eax,%r15d
lea    0xdf5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <read_int@plt>
mov    %eax,%r12d
mov    %r13,%rdi
call   10e0 <list_length@plt>
test   %r15d,%r15d
js     130c <main+0x13c>
cmp    %eax,%r15d
jge    130c <main+0x13c>
test   %r12d,%r12d
js     130c <main+0x13c>
cmp    %eax,%r12d
jge    130c <main+0x13c>
cmp    %r12d,%r15d
jne    1430 <main+0x260>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%r12
lea    0xd32(%rip),%r14
lea    0xd44(%rip),%rbx
lea    0xd55(%rip),%r15
jmp    1243 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xdf7(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <read_int@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   10e0 <list_length@plt>
test   %ebp,%ebp
js     1400 <main+0x230>
cmp    %eax,%ebp
jge    1400 <main+0x230>
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <list_get@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <person_get_spouse@plt>
test   %rax,%rax
je     1411 <main+0x241>
mov    %rbp,%rdi
call   1080 <divorce@plt>
jmp    123c <main+0x6c>
nopl   0x0(%rax,%rax,1)
lea    0xddb(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <read_int@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   10e0 <list_length@plt>
test   %ebp,%ebp
js     1230 <main+0x60>
cmp    %eax,%ebp
jge    1230 <main+0x60>
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <list_get@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %ebp,%esi
call   10b0 <list_remove_nth@plt>
mov    %rbx,%rdi
call   1070 <person_get_spouse@plt>
mov    %rbx,%rdi
lea    0xc77(%rip),%rbx
call   10d0 <die@plt>
jmp    123c <main+0x6c>
lea    0xd6d(%rip),%rdi
call   1040 <puts@plt>
jmp    123c <main+0x6c>
lea    0xd41(%rip),%rdi
call   1040 <puts@plt>
jmp    123c <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r15d,%esi
call   1050 <list_get@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %r12d,%esi
call   1050 <list_get@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1070 <person_get_spouse@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1070 <person_get_spouse@plt>
or     %rbp,%rax
je     1200 <main+0x30>
lea    0xc85(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%r12
jmp    120e <main+0x3e>
nopl   0x0(%rax)
mov    %r13,%rdi
xor    %esi,%esi
call   1050 <list_get@plt>
mov    %rax,%rbx
mov    %r13,%rdi
xor    %esi,%esi
call   10b0 <list_remove_nth@plt>
mov    %rbx,%rdi
call   1070 <person_get_spouse@plt>
mov    %rbx,%rdi
call   10d0 <die@plt>
mov    %r13,%rdi
call   10e0 <list_length@plt>
test   %eax,%eax
jne    1480 <main+0x2b0>
mov    %r13,%rdi
call   1030 <list_dispose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.arraylist = type { i32 }
%struct.person = type { i32 }
@.str = [35 x i8] c"Welcome to the Municipal Registry\0A\00"
@.str.1 = [7 x i8] c"Menu:\0A\00"
@.str.2 = [22 x i8] c" 1. Register birth.\0A\00"
@.str.3 = [25 x i8] c" 2. Register marriage.\0A\00"
@.str.4 = [24 x i8] c" 3. Register divorce.\0A\00"
@.str.5 = [22 x i8] c" 4. Register death.\0A\00"
@.str.6 = [12 x i8] c" 5. Exit.\0A\00"
@.str.7 = [38 x i8] c"Enter the index of the first person.\0A\00"
@.str.8 = [39 x i8] c"Enter the index of the second person.\0A\00"
@.str.9 = [39 x i8] c"One of the persons is already married.\00"
@.str.10 = [35 x i8] c"Index out of bounds or same index.\00"
@.str.11 = [27 x i8] c"Enter the husband's index.\00"
@.str.12 = [27 x i8] c"The person is not married.\00"
@.str.13 = [14 x i8] c"Invalid index\00"
@.str.14 = [24 x i8] c"Enter a person's index.\00"
@.str.15 = [15 x i8] c"Invalid index.\00"
@.str.16 = [15 x i8] c"Invalid Choice\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.arraylist*
%3 = alloca i32
%4 = alloca %struct.person*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.person*
%9 = alloca %struct.person*
%10 = alloca %struct.person*
%11 = alloca %struct.person*
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.person*
%15 = alloca %struct.person*
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.person*
%19 = alloca %struct.person*
%20 = alloca i32
%21 = alloca %struct.person*
%22 = alloca %struct.person*
store i32 0, i32* %1
%23 = call %struct.arraylist* (...) @create_arraylist()
store %struct.arraylist* %23, %struct.arraylist** %2
%24 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %0, %189
store i32 0, i32* %3
%26 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 (...) @read_int()
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %40
35: ; preds = %25
%36 = call %struct.person* (...) @create_person()
store %struct.person* %36, %struct.person** %4
%37 = load %struct.arraylist*, %struct.arraylist** %2
%38 = load %struct.person*, %struct.person** %4
%39 = call i32 @list_add(%struct.arraylist* %37, %struct.person* %38)
br label %189
40: ; preds = %25
%41 = load i32, i32* %3
%42 = icmp eq i32 %41, 2
br i1 %42, label %43, label %93
43: ; preds = %40
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store %struct.person* null, %struct.person** %8
store %struct.person* null, %struct.person** %9
store %struct.person* null, %struct.person** %10
store %struct.person* null, %struct.person** %11
%44 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%45 = call i32 (...) @read_int()
store i32 %45, i32* %5
%46 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0))
%47 = call i32 (...) @read_int()
store i32 %47, i32* %6
%48 = load %struct.arraylist*, %struct.arraylist** %2
%49 = call i32 @list_length(%struct.arraylist* %48)
store i32 %49, i32* %7
%50 = load i32, i32* %5
%51 = icmp sle i32 0, %50
br i1 %51, label %52, label %90
52: ; preds = %43
%53 = load i32, i32* %5
%54 = load i32, i32* %7
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %90
56: ; preds = %52
%57 = load i32, i32* %6
%58 = icmp sle i32 0, %57
br i1 %58, label %59, label %90
59: ; preds = %56
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %90
63: ; preds = %59
%64 = load i32, i32* %5
%65 = load i32, i32* %6
%66 = icmp ne i32 %64, %65
br i1 %66, label %67, label %90
67: ; preds = %63
%68 = load %struct.arraylist*, %struct.arraylist** %2
%69 = load i32, i32* %5
%70 = call %struct.person* @list_get(%struct.arraylist* %68, i32 %69)
store %struct.person* %70, %struct.person** %8
%71 = load %struct.arraylist*, %struct.arraylist** %2
%72 = load i32, i32* %6
%73 = call %struct.person* @list_get(%struct.arraylist* %71, i32 %72)
store %struct.person* %73, %struct.person** %9
%74 = load %struct.person*, %struct.person** %8
%75 = call %struct.person* @person_get_spouse(%struct.person* %74)
store %struct.person* %75, %struct.person** %10
%76 = load %struct.person*, %struct.person** %9
%77 = call %struct.person* @person_get_spouse(%struct.person* %76)
store %struct.person* %77, %struct.person** %11
%78 = load %struct.person*, %struct.person** %10
%79 = icmp eq %struct.person* %78, null
br i1 %79, label %80, label %87
80: ; preds = %67
%81 = load %struct.person*, %struct.person** %11
%82 = icmp eq %struct.person* %81, null
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load %struct.person*, %struct.person** %8
%85 = load %struct.person*, %struct.person** %9
%86 = call i32 @marry(%struct.person* %84, %struct.person* %85)
br label %89
87: ; preds = %80, %67
%88 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
br label %89
89: ; preds = %87, %83
br label %92
90: ; preds = %63, %59, %56, %52, %43
%91 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0))
br label %92
92: ; preds = %90, %89
br label %188
93: ; preds = %40
%94 = load i32, i32* %3
%95 = icmp eq i32 %94, 3
br i1 %95, label %96, label %124
96: ; preds = %93
store i32 0, i32* %12
store i32 0, i32* %13
store %struct.person* null, %struct.person** %14
store %struct.person* null, %struct.person** %15
%97 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%98 = call i32 (...) @read_int()
store i32 %98, i32* %12
%99 = load %struct.arraylist*, %struct.arraylist** %2
%100 = call i32 @list_length(%struct.arraylist* %99)
store i32 %100, i32* %13
%101 = load i32, i32* %12
%102 = icmp sle i32 0, %101
br i1 %102, label %103, label %121
103: ; preds = %96
%104 = load i32, i32* %12
%105 = load i32, i32* %13
%106 = icmp slt i32 %104, %105
br i1 %106, label %107, label %121
107: ; preds = %103
%108 = load %struct.arraylist*, %struct.arraylist** %2
%109 = load i32, i32* %12
%110 = call %struct.person* @list_get(%struct.arraylist* %108, i32 %109)
store %struct.person* %110, %struct.person** %14
%111 = load %struct.person*, %struct.person** %14
%112 = call %struct.person* @person_get_spouse(%struct.person* %111)
store %struct.person* %112, %struct.person** %15
%113 = load %struct.person*, %struct.person** %15
%114 = icmp ne %struct.person* %113, null
br i1 %114, label %115, label %118
115: ; preds = %107
%116 = load %struct.person*, %struct.person** %14
%117 = call i32 @divorce(%struct.person* %116)
br label %120
118: ; preds = %107
%119 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
br label %120
120: ; preds = %118, %115
br label %123
121: ; preds = %103, %96
%122 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
br label %123
123: ; preds = %121, %120
br label %187
124: ; preds = %93
%125 = load i32, i32* %3
%126 = icmp eq i32 %125, 4
br i1 %126, label %127, label %160
127: ; preds = %124
store i32 0, i32* %16
store i32 0, i32* %17
store %struct.person* null, %struct.person** %18
store %struct.person* null, %struct.person** %19
%128 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.14, i64 0, i64 0))
%129 = call i32 (...) @read_int()
store i32 %129, i32* %16
%130 = load %struct.arraylist*, %struct.arraylist** %2
%131 = call i32 @list_length(%struct.arraylist* %130)
store i32 %131, i32* %17
%132 = load i32, i32* %16
%133 = icmp sle i32 0, %132
br i1 %133, label %134, label %157
134: ; preds = %127
%135 = load i32, i32* %16
%136 = load i32, i32* %17
%137 = icmp slt i32 %135, %136
br i1 %137, label %138, label %157
138: ; preds = %134
%139 = load %struct.arraylist*, %struct.arraylist** %2
%140 = load i32, i32* %16
%141 = call %struct.person* @list_get(%struct.arraylist* %139, i32 %140)
store %struct.person* %141, %struct.person** %18
%142 = load %struct.arraylist*, %struct.arraylist** %2
%143 = load i32, i32* %16
%144 = call i32 @list_remove_nth(%struct.arraylist* %142, i32 %143)
%145 = load %struct.person*, %struct.person** %18
%146 = call %struct.person* @person_get_spouse(%struct.person* %145)
store %struct.person* %146, %struct.person** %19
%147 = load %struct.person*, %struct.person** %19
%148 = icmp ne %struct.person* %147, null
br i1 %148, label %149, label %150
149: ; preds = %138
br label %150
150: ; preds = %149, %138
%151 = load %struct.person*, %struct.person** %18
%152 = call i32 @die(%struct.person* %151)
%153 = load %struct.person*, %struct.person** %19
%154 = icmp ne %struct.person* %153, null
br i1 %154, label %155, label %156
155: ; preds = %150
br label %156
156: ; preds = %155, %150
br label %159
157: ; preds = %134, %127
%158 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0))
br label %159
159: ; preds = %157, %156
br label %186
160: ; preds = %124
%161 = load i32, i32* %3
%162 = icmp eq i32 %161, 5
br i1 %162, label %163, label %183
163: ; preds = %160
%164 = load %struct.arraylist*, %struct.arraylist** %2
%165 = call i32 @list_length(%struct.arraylist* %164)
store i32 %165, i32* %20
br label %166
166: ; preds = %169, %163
%167 = load i32, i32* %20
%168 = icmp ne i32 %167, 0
br i1 %168, label %169, label %180
169: ; preds = %166
%170 = load %struct.arraylist*, %struct.arraylist** %2
%171 = call %struct.person* @list_get(%struct.arraylist* %170, i32 0)
store %struct.person* %171, %struct.person** %21
store %struct.person* null, %struct.person** %22
%172 = load %struct.arraylist*, %struct.arraylist** %2
%173 = call i32 @list_remove_nth(%struct.arraylist* %172, i32 0)
%174 = load %struct.person*, %struct.person** %21
%175 = call %struct.person* @person_get_spouse(%struct.person* %174)
store %struct.person* %175, %struct.person** %22
%176 = load %struct.person*, %struct.person** %21
%177 = call i32 @die(%struct.person* %176)
%178 = load %struct.arraylist*, %struct.arraylist** %2
%179 = call i32 @list_length(%struct.arraylist* %178)
store i32 %179, i32* %20
br label %166
180: ; preds = %166
%181 = load %struct.arraylist*, %struct.arraylist** %2
%182 = call i32 @list_dispose(%struct.arraylist* %181)
ret i32 0
183: ; preds = %160
%184 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0))
br label %185
185: ; preds = %183
br label %186
186: ; preds = %185, %159
br label %187
187: ; preds = %186, %123
br label %188
188: ; preds = %187, %92
br label %189
189: ; preds = %188, %35
br label %25
}

LLVM IR (-O2):
%struct.arraylist = type { i32 }
%struct.person = type { i32 }
@.str = [35 x i8] c"Welcome to the Municipal Registry\0A\00"
@.str.1 = [7 x i8] c"Menu:\0A\00"
@.str.2 = [22 x i8] c" 1. Register birth.\0A\00"
@.str.3 = [25 x i8] c" 2. Register marriage.\0A\00"
@.str.4 = [24 x i8] c" 3. Register divorce.\0A\00"
@.str.5 = [22 x i8] c" 4. Register death.\0A\00"
@.str.6 = [12 x i8] c" 5. Exit.\0A\00"
@.str.7 = [38 x i8] c"Enter the index of the first person.\0A\00"
@.str.8 = [39 x i8] c"Enter the index of the second person.\0A\00"
@.str.9 = [39 x i8] c"One of the persons is already married.\00"
@.str.10 = [35 x i8] c"Index out of bounds or same index.\00"
@.str.11 = [27 x i8] c"Enter the husband's index.\00"
@.str.12 = [27 x i8] c"The person is not married.\00"
@.str.13 = [14 x i8] c"Invalid index\00"
@.str.14 = [24 x i8] c"Enter a person's index.\00"
@.str.15 = [15 x i8] c"Invalid index.\00"
@.str.16 = [15 x i8] c"Invalid Choice\00"
define i32 @main() {
%1 = tail call %struct.arraylist* (...) @create_arraylist()
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %14, %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%10 = tail call i32 (...) @read_int()
switch i32 %10, label %87 [
i32 1, label %11
i32 2, label %15
i32 3, label %44
i32 4, label %61
i32 5, label %75
]
11: ; preds = %3
%12 = tail call %struct.person* (...) @create_person()
%13 = tail call i32 @list_add(%struct.arraylist* %1, %struct.person* %12)
br label %14
14: ; preds = %11, %87, %38, %40, %42, %55, %57, %59, %73, %68
br label %3
15: ; preds = %3
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%17 = tail call i32 (...) @read_int()
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0))
%19 = tail call i32 (...) @read_int()
%20 = tail call i32 @list_length(%struct.arraylist* %1)
%21 = icmp sgt i32 %17, -1
br i1 %21, label %22, label %42
22: ; preds = %15
%23 = icmp sge i32 %17, %20
%24 = icmp slt i32 %19, 0
%25 = select i1 %23, i1 true, i1 %24
%26 = icmp sge i32 %19, %20
%27 = select i1 %25, i1 true, i1 %26
%28 = icmp eq i32 %17, %19
%29 = select i1 %27, i1 true, i1 %28
br i1 %29, label %42, label %30
30: ; preds = %22
%31 = tail call %struct.person* @list_get(%struct.arraylist* %1, i32 %17)
%32 = tail call %struct.person* @list_get(%struct.arraylist* %1, i32 %19)
%33 = tail call %struct.person* @person_get_spouse(%struct.person* %31)
%34 = tail call %struct.person* @person_get_spouse(%struct.person* %32)
%35 = icmp eq %struct.person* %33, null
%36 = icmp eq %struct.person* %34, null
%37 = select i1 %35, i1 %36, i1 false
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = tail call i32 @marry(%struct.person* %31, %struct.person* %32)
br label %14
40: ; preds = %30
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
br label %14
42: ; preds = %22, %15
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0))
br label %14
44: ; preds = %3
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%46 = tail call i32 (...) @read_int()
%47 = tail call i32 @list_length(%struct.arraylist* %1)
%48 = icmp sgt i32 %46, -1
%49 = icmp slt i32 %46, %47
%50 = select i1 %48, i1 %49, i1 false
br i1 %50, label %51, label %59
51: ; preds = %44
%52 = tail call %struct.person* @list_get(%struct.arraylist* %1, i32 %46)
%53 = tail call %struct.person* @person_get_spouse(%struct.person* %52)
%54 = icmp eq %struct.person* %53, null
br i1 %54, label %57, label %55
55: ; preds = %51
%56 = tail call i32 @divorce(%struct.person* %52)
br label %14
57: ; preds = %51
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
br label %14
59: ; preds = %44
%60 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
br label %14
61: ; preds = %3
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.14, i64 0, i64 0))
%63 = tail call i32 (...) @read_int()
%64 = tail call i32 @list_length(%struct.arraylist* %1)
%65 = icmp sgt i32 %63, -1
%66 = icmp slt i32 %63, %64
%67 = select i1 %65, i1 %66, i1 false
br i1 %67, label %68, label %73
68: ; preds = %61
%69 = tail call %struct.person* @list_get(%struct.arraylist* %1, i32 %63)
%70 = tail call i32 @list_remove_nth(%struct.arraylist* %1, i32 %63)
%71 = tail call %struct.person* @person_get_spouse(%struct.person* %69)
%72 = tail call i32 @die(%struct.person* %69)
br label %14
73: ; preds = %61
%74 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0))
br label %14
75: ; preds = %3
%76 = tail call i32 @list_length(%struct.arraylist* %1)
%77 = icmp eq i32 %76, 0
br i1 %77, label %85, label %78
78: ; preds = %75, %78
%79 = tail call %struct.person* @list_get(%struct.arraylist* %1, i32 0)
%80 = tail call i32 @list_remove_nth(%struct.arraylist* %1, i32 0)
%81 = tail call %struct.person* @person_get_spouse(%struct.person* %79)
%82 = tail call i32 @die(%struct.person* %79)
%83 = tail call i32 @list_length(%struct.arraylist* %1)
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %78
85: ; preds = %78, %75
%86 = tail call i32 @list_dispose(%struct.arraylist* %1)
ret i32 0
87: ; preds = %3
%88 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0))
br label %14
}