#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 */
typedef size_t int64_t;

/* Variables and functions */
int /*<<< orphan*/ close_rsocket(size_t);
void close_connection(int64_t cs, int64_t *cslist, int64_t *num_cs) {
  int64_t i;
  for (i = 0; i < *num_cs; i++) {
    if (cslist[i] == cs) {
      close_rsocket(cslist[i]);
      *num_cs = (*num_cs) - 1;
      cslist[i] = cslist[*num_cs];
      break;
    }
  }
}


x86 assembly (clang, -O0):
<close_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jae    11ac <close_connection+0x9c>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x8(%rbp),%rax
jne    1196 <close_connection+0x86>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <close_rsocket@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
sub    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11ac <close_connection+0x9c>
jmp    119b <close_connection+0x8b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <close_connection+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_connection>:
push   %r15
push   %r14
push   %rbx
mov    (%rdx),%rax
test   %rax,%rax
je     1159 <close_connection+0x49>
mov    %rdx,%r14
mov    %rsi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %rdi,(%r15,%rbx,8)
je     1141 <close_connection+0x31>
add    $0x1,%rbx
cmp    %rbx,%rax
jne    1130 <close_connection+0x20>
jmp    1159 <close_connection+0x49>
call   1030 <close_rsocket@plt>
mov    (%r14),%rax
lea    -0x1(%rax),%rcx
mov    %rcx,(%r14)
mov    -0x8(%r15,%rax,8),%rax
mov    %rax,(%r15,%rbx,8)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @close_connection(i64 %0, i64* %1, i64* %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64
store i64 %0, i64* %4
store i64* %1, i64** %5
store i64* %2, i64** %6
store i64 0, i64* %7
br label %8
8: ; preds = %39, %3
%9 = load i64, i64* %7
%10 = load i64*, i64** %6
%11 = load i64, i64* %10
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %42
13: ; preds = %8
%14 = load i64*, i64** %5
%15 = load i64, i64* %7
%16 = getelementptr inbounds i64, i64* %14, i64 %15
%17 = load i64, i64* %16
%18 = load i64, i64* %4
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %13
%21 = load i64*, i64** %5
%22 = load i64, i64* %7
%23 = getelementptr inbounds i64, i64* %21, i64 %22
%24 = load i64, i64* %23
%25 = call i32 @close_rsocket(i64 %24)
%26 = load i64*, i64** %6
%27 = load i64, i64* %26
%28 = sub i64 %27, 1
%29 = load i64*, i64** %6
store i64 %28, i64* %29
%30 = load i64*, i64** %5
%31 = load i64*, i64** %6
%32 = load i64, i64* %31
%33 = getelementptr inbounds i64, i64* %30, i64 %32
%34 = load i64, i64* %33
%35 = load i64*, i64** %5
%36 = load i64, i64* %7
%37 = getelementptr inbounds i64, i64* %35, i64 %36
store i64 %34, i64* %37
br label %42
38: ; preds = %13
br label %39
39: ; preds = %38
%40 = load i64, i64* %7
%41 = add i64 %40, 1
store i64 %41, i64* %7
br label %8
42: ; preds = %20, %8
ret void
}

LLVM IR (-O2):
define void @close_connection(i64 %0, i64* nocapture %1, i64* nocapture %2) {
%4 = load i64, i64* %2
%5 = icmp eq i64 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3, %18
%7 = phi i64 [ %19, %18 ], [ 0, %3 ]
%8 = getelementptr inbounds i64, i64* %1, i64 %7
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, %0
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = getelementptr inbounds i64, i64* %1, i64 %7
%13 = tail call i32 @close_rsocket(i64 %0)
%14 = load i64, i64* %2
%15 = add i64 %14, -1
store i64 %15, i64* %2
%16 = getelementptr inbounds i64, i64* %1, i64 %15
%17 = load i64, i64* %16
store i64 %17, i64* %12
br label %21
18: ; preds = %6
%19 = add nuw i64 %7, 1
%20 = icmp eq i64 %19, %4
br i1 %20, label %21, label %6
21: ; preds = %18, %3, %11
ret void
}