#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
char **realloc(char **, int);
void add_to_state(char ***ifaces, int *n_ifaces, int *max_ifaces,
                  char *new_iface) {
  assert(*max_ifaces >= *n_ifaces);
  if (*max_ifaces == *n_ifaces) {
    *max_ifaces = (*max_ifaces * 2) + 1;
    *ifaces = realloc(*ifaces, sizeof(**ifaces) * *max_ifaces);
    if (*ifaces == NULL) {
      perror("realloc");
      exit(1);
    }
  }
  (*ifaces)[(*n_ifaces)++] = new_iface;
}


x86 assembly (clang, -O0):
<add_to_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jne    11e1 <add_to_state+0xa1>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11dc <add_to_state+0x9c>
lea    0xe33(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11e1 <add_to_state+0xa1>
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_state>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    (%rdx),%eax
xor    %edi,%edi
cmp    (%rsi),%eax
setge  %dil
call   1030 <assert@plt>
mov    (%rbx),%eax
mov    (%r12),%ecx
cmp    %ecx,%eax
jne    1195 <add_to_state+0x55>
mov    %eax,%ecx
add    %ecx,%ecx
add    %eax,%eax
add    $0x1,%eax
mov    %eax,(%rbx)
mov    (%r15),%rdi
lea    0x8(,%rcx,8),%esi
call   1040 <realloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11b2 <add_to_state+0x72>
mov    (%r12),%ecx
jmp    1198 <add_to_state+0x58>
mov    (%r15),%rax
lea    0x1(%rcx),%edx
mov    %edx,(%r12)
movslq %ecx,%rcx
mov    %r14,(%rax,%rcx,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe47(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"realloc\00"
define void @add_to_state(i8*** %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i8***
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
store i8*** %0, i8**** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%9 = load i32*, i32** %7
%10 = load i32, i32* %9
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = icmp sge i32 %10, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32*, i32** %7
%17 = load i32, i32* %16
%18 = load i32*, i32** %6
%19 = load i32, i32* %18
%20 = icmp eq i32 %17, %19
br i1 %20, label %21, label %43
21: ; preds = %4
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = mul nsw i32 %23, 2
%25 = add nsw i32 %24, 1
%26 = load i32*, i32** %7
store i32 %25, i32* %26
%27 = load i8***, i8**** %5
%28 = load i8**, i8*** %27
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = mul i64 8, %31
%33 = trunc i64 %32 to i32
%34 = call i8** @realloc(i8** %28, i32 %33)
%35 = load i8***, i8**** %5
store i8** %34, i8*** %35
%36 = load i8***, i8**** %5
%37 = load i8**, i8*** %36
%38 = icmp eq i8** %37, null
br i1 %38, label %39, label %42
39: ; preds = %21
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %21
br label %43
43: ; preds = %42, %4
%44 = load i8*, i8** %8
%45 = load i8***, i8**** %5
%46 = load i8**, i8*** %45
%47 = load i32*, i32** %6
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 1
store i32 %49, i32* %47
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8*, i8** %46, i64 %50
store i8* %44, i8** %51
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"realloc\00"
define void @add_to_state(i8*** nocapture %0, i32* nocapture %1, i32* nocapture %2, i8* %3) {
%5 = load i32, i32* %2
%6 = load i32, i32* %1
%7 = icmp sge i32 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = icmp eq i32 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %4
%14 = load i8**, i8*** %0
br label %27
15: ; preds = %4
%16 = shl nsw i32 %10, 1
%17 = or i32 %16, 1
store i32 %17, i32* %2
%18 = load i8**, i8*** %0
%19 = shl i32 %17, 3
%20 = tail call i8** @realloc(i8** %18, i32 %19)
store i8** %20, i8*** %0
%21 = icmp eq i8** %20, null
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = load i32, i32* %1
br label %27
24: ; preds = %15
%25 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %22, %13
%28 = phi i32 [ %11, %13 ], [ %23, %22 ]
%29 = phi i8** [ %14, %13 ], [ %20, %22 ]
%30 = add nsw i32 %28, 1
store i32 %30, i32* %1
%31 = sext i32 %28 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
store i8* %3, i8** %32
ret void
}