#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*/ Log(char *);
scalar_t__ close(int);
int /*<<< orphan*/ free(int *);
int cleanup(int servfd, int *client_fd, int client_count) {
  Log("Shutdown");
  int i;
  for (i = 0; i < client_count; ++i)
    if (close(client_fd[i]) < 0)
      return -1;
  free(client_fd);
  Log("- Closing server socket");
  if (close(servfd) < 0)
    return -1;
  Log("Shutdown complete");
  return 0;
}


x86 assembly (clang, -O0):
<cleanup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xeb7(%rip),%rdi
call   1050 <Log@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119a <cleanup+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1187 <cleanup+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <cleanup+0xb0>
jmp    118c <cleanup+0x5c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1155 <cleanup+0x25>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe5f(%rip),%rdi
call   1050 <Log@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    11cd <cleanup+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <cleanup+0xb0>
lea    0xe4d(%rip),%rdi
call   1050 <Log@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanup>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %edi,%r14d
lea    0xeba(%rip),%rdi
call   1050 <Log@plt>
test   %ebp,%ebp
jle    1177 <cleanup+0x47>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15,%rbx,4),%edi
call   1040 <close@plt>
test   %rax,%rax
js     11a8 <cleanup+0x78>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <cleanup+0x30>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe83(%rip),%rdi
call   1050 <Log@plt>
mov    %r14d,%edi
call   1040 <close@plt>
test   %rax,%rax
js     11a8 <cleanup+0x78>
lea    0xe82(%rip),%rdi
call   1050 <Log@plt>
xor    %eax,%eax
jmp    11ad <cleanup+0x7d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"Shutdown\00"
@.str.1 = [24 x i8] c"- Closing server socket\00"
@.str.2 = [18 x i8] c"Shutdown complete\00"
define i32 @cleanup(i32 %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @Log(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %10
8: ; preds = %10
%9 = icmp eq i64 %16, %7
br i1 %9, label %17, label %10
10: ; preds = %6, %8
%11 = phi i64 [ 0, %6 ], [ %16, %8 ]
%12 = getelementptr inbounds i32, i32* %1, i64 %11
%13 = load i32, i32* %12
%14 = tail call i64 @close(i32 %13)
%15 = icmp slt i64 %14, 0
%16 = add nuw nsw i64 %11, 1
br i1 %15, label %24, label %8
17: ; preds = %8, %3
%18 = tail call i32 @free(i32* %1)
%19 = tail call i32 @Log(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i64 @close(i32 %0)
%21 = icmp slt i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = tail call i32 @Log(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %10, %17, %22
%25 = phi i32 [ 0, %22 ], [ -1, %17 ], [ -1, %10 ]
ret i32 %25
}