#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 close_client(int, int, int *, int *, int *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int assign_socket(int c_type, int connected, int current_sock, int *sockets,
                  int *sockets_s, int *map_sockets) {
  if (map_sockets[c_type] == -1) {
    map_sockets[c_type] = current_sock;
  } else {
    puts("Client already exists.");
    write(sockets[current_sock], "CLOSE", 5);
    usleep(100);
    connected =
        close_client(connected, current_sock, sockets, sockets_s, map_sockets);
  }
  return connected;
}


x86 assembly (clang, -O0):
<assign_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
jne    1182 <assign_socket+0x42>
mov    -0xc(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11ce <assign_socket+0x8e>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    0xe77(%rip),%rsi
mov    $0x5,%edx
call   1050 <write@plt>
mov    $0x64,%edi
call   1060 <usleep@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1040 <close_client@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assign_socket>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r9,%rbx
mov    %edx,%ebp
mov    %esi,%r12d
movslq %edi,%rax
cmpl   $0xffffffff,(%r9,%rax,4)
je     11a9 <assign_socket+0x69>
mov    %r8,%r14
mov    %rcx,%r15
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
movslq %ebp,%rbp
mov    (%r15,%rbp,4),%edi
lea    0xe9d(%rip),%rsi
mov    $0x5,%edx
call   1050 <write@plt>
mov    $0x64,%edi
call   1060 <usleep@plt>
mov    %r12d,%edi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close_client@plt>
mov    %ebp,(%rbx,%rax,4)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Client already exists.\00"
@.str.1 = [6 x i8] c"CLOSE\00"
define i32 @assign_socket(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%13 = load i32*, i32** %12
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %6
%20 = load i32, i32* %9
%21 = load i32*, i32** %12
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
br label %40
25: ; preds = %6
%26 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%27 = load i32*, i32** %10
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call i32 @write(i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%33 = call i32 @usleep(i32 100)
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = load i32*, i32** %10
%37 = load i32*, i32** %11
%38 = load i32*, i32** %12
%39 = call i32 @close_client(i32 %34, i32 %35, i32* %36, i32* %37, i32* %38)
store i32 %39, i32* %8
br label %40
40: ; preds = %25, %19
%41 = load i32, i32* %8
ret i32 %41
}

LLVM IR (-O2):
@.str = [23 x i8] c"Client already exists.\00"
@.str.1 = [6 x i8] c"CLOSE\00"
define i32 @assign_socket(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = sext i32 %0 to i64
%8 = getelementptr inbounds i32, i32* %5, i64 %7
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %6
store i32 %2, i32* %8
br label %20
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = sext i32 %2 to i64
%15 = getelementptr inbounds i32, i32* %3, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 @write(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%18 = tail call i32 @usleep(i32 100)
%19 = tail call i32 @close_client(i32 %1, i32 %2, i32* %3, i32* %4, i32* %5)
br label %20
20: ; preds = %12, %11
%21 = phi i32 [ %1, %11 ], [ %19, %12 ]
ret i32 %21
}