#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 /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dbgprintf(char *, int);
int /*<<< orphan*/ free(int *);
void freeAllSockets(int **socks) {
  assert(socks != NULL);
  assert(*socks != NULL);
  while (**socks) {
    dbgprintf("Closing socket %d.\n", (*socks)[**socks]);
    close((*socks)[**socks]);
    (**socks)--;
  }
  free(*socks);
  *socks = NULL;
}


x86 assembly (clang, -O0):
<freeAllSockets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,(%rax)
je     11cf <freeAllSockets+0x8f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe62(%rip),%rdi
call   1060 <dbgprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    1173 <freeAllSockets+0x33>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<freeAllSockets>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rbx)
setne  %dil
call   1050 <assert@plt>
mov    (%rbx),%rdi
mov    (%rdi),%eax
test   %eax,%eax
je     11a7 <freeAllSockets+0x67>
lea    0xe8c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cltq
mov    (%rdi,%rax,4),%esi
mov    %r14,%rdi
call   1060 <dbgprintf@plt>
mov    (%rbx),%rax
movslq (%rax),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <close@plt>
mov    (%rbx),%rdi
mov    (%rdi),%eax
add    $0xffffffff,%eax
mov    %eax,(%rdi)
jne    1180 <freeAllSockets+0x40>
call   1030 <free@plt>
movq   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Closing socket %d.\0A\00"
define void @freeAllSockets(i32** %0) {
%2 = alloca i32**
store i32** %0, i32*** %2
%3 = load i32**, i32*** %2
%4 = icmp ne i32** %3, null
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = load i32**, i32*** %2
%8 = load i32*, i32** %7
%9 = icmp ne i32* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
br label %12
12: ; preds = %17, %1
%13 = load i32**, i32*** %2
%14 = load i32*, i32** %13
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %40
17: ; preds = %12
%18 = load i32**, i32*** %2
%19 = load i32*, i32** %18
%20 = load i32**, i32*** %2
%21 = load i32*, i32** %20
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %19, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @dbgprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32**, i32*** %2
%28 = load i32*, i32** %27
%29 = load i32**, i32*** %2
%30 = load i32*, i32** %29
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %28, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
%36 = load i32**, i32*** %2
%37 = load i32*, i32** %36
%38 = load i32, i32* %37
%39 = add nsw i32 %38, -1
store i32 %39, i32* %37
br label %12
40: ; preds = %12
%41 = load i32**, i32*** %2
%42 = load i32*, i32** %41
%43 = call i32 @free(i32* %42)
%44 = load i32**, i32*** %2
store i32* null, i32** %44
ret void
}

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