#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 int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int close(int);
int /*<<< orphan*/ create_addr(int, int, int *);
int /*<<< orphan*/ genera_id();
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ htonll(int /*<<< orphan*/);
int *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ usleep(int);
int write(int, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  uint64_t id, n_id;
  int secret, i, j, n, p, k, w;
  sscanf(argv[1], "%d", &p);
  sscanf(argv[2], "%d", &k);
  sscanf(argv[3], "%d", &w);
  srand(getpid());
  secret = (rand() % 3000) + 1;
  id = genera_id();
  printf("CLIENT %016llX SECRET %d\n", id, secret);
  int *cs = malloc(p * sizeof(int));
  create_addr(k, p, cs);
  n_id = htonll(id);
  int usecret = secret * 1000;
  for (i = 0; i < w; i++) {
    j = rand() % p;
    if ((n = write(cs[j], &n_id, sizeof(uint64_t))) != sizeof(uint64_t))
      perror("client: error writing in the socket");
    usleep(usecret);
  }
  for (i = 0; i < p; i++)
    if (close(cs[i]) == -1)
      perror("client:closing sockets");
  printf("CLIENT %016llX DONE\n", id);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0b(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   10a0 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf3(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   10a0 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xddb(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   10a0 <sscanf@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    $0x0,%al
call   10d0 <rand@plt>
mov    $0xbb8,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   10c0 <genera_id@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x40(%rbp),%rdx
call   1030 <create_addr@plt>
mov    -0x14(%rbp),%edi
call   10f0 <htonll@plt>
mov    %eax,-0x18(%rbp)
imul   $0x3e8,-0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1311 <main+0x141>
mov    $0x0,%al
call   10d0 <rand@plt>
cltd
idivl  -0x2c(%rbp)
mov    %edx,-0x24(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,-0x28(%rbp)
cltq
cmp    $0x4,%rax
je     12fb <main+0x12b>
lea    0xd27(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x44(%rbp),%edi
call   10e0 <usleep@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12ad <main+0xdd>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    135c <main+0x18c>
mov    -0x40(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1349 <main+0x179>
lea    0xcfd(%rip),%rdi
call   10b0 <perror@plt>
jmp    134e <main+0x17e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1318 <main+0x148>
mov    -0x14(%rbp),%esi
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe14(%rip),%rbp
lea    0x8(%rsp),%rdx
mov    %rbp,%rsi
call   10a0 <sscanf@plt>
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rdx
mov    %rbp,%rsi
call   10a0 <sscanf@plt>
mov    0x18(%rbx),%rdi
lea    0xc(%rsp),%rdx
mov    %rbp,%rsi
call   10a0 <sscanf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
cltq
imul   $0x57619f1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0xbb8,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r15d
add    $0x1,%r15d
xor    %eax,%eax
call   10c0 <genera_id@plt>
mov    %eax,%r14d
lea    0xd9c(%rip),%rdi
mov    %eax,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%ebp
lea    0x0(,%rbp,4),%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%edi
mov    %ebp,%esi
mov    %rax,%rdx
call   1030 <create_addr@plt>
mov    %r14d,%edi
call   10f0 <htonll@plt>
mov    %eax,0x14(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    12ff <main+0x12f>
imul   $0x3e8,%r15d,%r13d
lea    0x14(%rsp),%r15
lea    0xd63(%rip),%r12
xor    %ebp,%ebp
jmp    12d1 <main+0x101>
xchg   %ax,%ax
mov    %r13d,%edi
call   10e0 <usleep@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jge    12ff <main+0x12f>
xor    %eax,%eax
call   10d0 <rand@plt>
cltd
idivl  0x8(%rsp)
movslq %edx,%rax
mov    (%rbx,%rax,4),%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x4,%eax
je     12c0 <main+0xf0>
mov    %r12,%rdi
call   10b0 <perror@plt>
jmp    12c0 <main+0xf0>
cmpl   $0x0,0x8(%rsp)
jle    1345 <main+0x175>
xor    %ebp,%ebp
lea    0xd32(%rip),%r15
jmp    132e <main+0x15e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
cmp    %rax,%rbp
jge    1345 <main+0x175>
mov    (%rbx,%rbp,4),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1320 <main+0x150>
mov    %r15,%rdi
call   10b0 <perror@plt>
jmp    1320 <main+0x150>
lea    0xd0c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [26 x i8] c"CLIENT %016llX SECRET %d\0A\00"
@.str.2 = [36 x i8] c"client: error writing in the socket\00"
@.str.3 = [23 x i8] c"client:closing sockets\00"
@.str.4 = [21 x i8] c"CLIENT %016llX DONE\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %12)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %14)
%29 = call i32 (...) @getpid()
%30 = call i32 @srand(i32 %29)
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 3000
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
%34 = call i32 (...) @genera_id()
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
%38 = load i32, i32* %12
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 4
%41 = trunc i64 %40 to i32
%42 = call i32* @malloc(i32 %41)
store i32* %42, i32** %15
%43 = load i32, i32* %13
%44 = load i32, i32* %12
%45 = load i32*, i32** %15
%46 = call i32 @create_addr(i32 %43, i32 %44, i32* %45)
%47 = load i32, i32* %6
%48 = call i32 @htonll(i32 %47)
store i32 %48, i32* %7
%49 = load i32, i32* %8
%50 = mul nsw i32 %49, 1000
store i32 %50, i32* %16
store i32 0, i32* %9
br label %51
51: ; preds = %72, %2
%52 = load i32, i32* %9
%53 = load i32, i32* %14
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %75
55: ; preds = %51
%56 = call i32 (...) @rand()
%57 = load i32, i32* %12
%58 = srem i32 %56, %57
store i32 %58, i32* %10
%59 = load i32*, i32** %15
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 @write(i32 %63, i32* %7, i32 4)
store i32 %64, i32* %11
%65 = sext i32 %64 to i64
%66 = icmp ne i64 %65, 4
br i1 %66, label %67, label %69
67: ; preds = %55
%68 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %69
69: ; preds = %67, %55
%70 = load i32, i32* %16
%71 = call i32 @usleep(i32 %70)
br label %72
72: ; preds = %69
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %51
75: ; preds = %51
store i32 0, i32* %9
br label %76
76: ; preds = %91, %75
%77 = load i32, i32* %9
%78 = load i32, i32* %12
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %94
80: ; preds = %76
%81 = load i32*, i32** %15
%82 = load i32, i32* %9
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %81, i64 %83
%85 = load i32, i32* %84
%86 = call i32 @close(i32 %85)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %90
88: ; preds = %80
%89 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %90
90: ; preds = %88, %80
br label %91
91: ; preds = %90
%92 = load i32, i32* %9
%93 = add nsw i32 %92, 1
store i32 %93, i32* %9
br label %76
94: ; preds = %76
%95 = load i32, i32* %6
%96 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %95)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [26 x i8] c"CLIENT %016llX SECRET %d\0A\00"
@.str.2 = [36 x i8] c"client: error writing in the socket\00"
@.str.3 = [23 x i8] c"client:closing sockets\00"
@.str.4 = [21 x i8] c"CLIENT %016llX DONE\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%20 = call i32 (...) @getpid()
%21 = call i32 @srand(i32 %20)
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 3000
%24 = add nsw i32 %23, 1
%25 = call i32 (...) @genera_id()
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %24)
%27 = load i32, i32* %4
%28 = shl i32 %27, 2
%29 = call i32* @malloc(i32 %28)
%30 = load i32, i32* %5
%31 = call i32 @create_addr(i32 %30, i32 %27, i32* %29)
%32 = call i32 @htonll(i32 %25)
store i32 %32, i32* %3
%33 = mul nsw i32 %24, 1000
%34 = load i32, i32* %6
%35 = icmp sgt i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %51, %2
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 0
br i1 %38, label %56, label %69
39: ; preds = %2, %51
%40 = phi i32 [ %53, %51 ], [ 0, %2 ]
%41 = call i32 (...) @rand()
%42 = load i32, i32* %4
%43 = srem i32 %41, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %29, i64 %44
%46 = load i32, i32* %45
%47 = call i32 @write(i32 %46, i32* %3, i32 4)
%48 = icmp eq i32 %47, 4
br i1 %48, label %51, label %49
49: ; preds = %39
%50 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %49, %39
%52 = call i32 @usleep(i32 %33)
%53 = add nuw nsw i32 %40, 1
%54 = load i32, i32* %6
%55 = icmp slt i32 %53, %54
br i1 %55, label %39, label %36
56: ; preds = %36, %64
%57 = phi i64 [ %65, %64 ], [ 0, %36 ]
%58 = getelementptr inbounds i32, i32* %29, i64 %57
%59 = load i32, i32* %58
%60 = call i32 @close(i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %64
64: ; preds = %56, %62
%65 = add nuw nsw i64 %57, 1
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = icmp slt i64 %65, %67
br i1 %68, label %56, label %69
69: ; preds = %64, %36
%70 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %25)
ret i32 0
}