#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc != 2 || atoi(argv[1]) > 4 - 1 || atoi(argv[1]) < 0) {
    printf("\n Use: ./client <id> \n id belongs to [0,N_PROCESSUS] \n "
           "N_PROCESSUS is a #define in server.c and client.c \n");
    return (1);
  }
  int clientSocket, portNum, nBytes, v, t;
  char buffer[1024];
  char value[32];
  char *id;
  struct sockaddr_in serverAddr;
  socklen_t addr_size;
  portNum = 7891;
  clientSocket = socket(PF_INET, SOCK_DGRAM, 0);
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(portNum);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
  addr_size = sizeof serverAddr;
  id = argv[1];
  while (1) {
    v = rand() % 100;
    sprintf(value, "%d", v);
    strcpy(buffer, id);
    strcat(buffer, ":");
    strcat(buffer, value);
    printf("%s", buffer);
    nBytes = strlen(buffer) + 1;
    sendto(clientSocket, buffer, nBytes, 0, (struct sockaddr *)&serverAddr,
           addr_size);
    t = rand() % 10;
    sleep(t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    121f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
cmp    $0x3,%eax
jg     121f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
cmp    $0x0,%eax
jge    123b <main+0x6b>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x470,%rsp
pop    %rbp
ret
movl   $0x1ed3,-0x18(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x45c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x460(%rbp)
lea    0xde9(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x464(%rbp)
mov    -0x468(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
movl   $0x10,-0x46c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x458(%rbp)
mov    $0x0,%al
call   10e0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
lea    -0x450(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xd9a(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x430(%rbp),%rdi
mov    -0x458(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x430(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x430(%rbp),%rdi
lea    -0x450(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x430(%rbp),%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x470(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x468(%rbp),%r8
mov    -0x46c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   10d0 <sleep@plt>
jmp    12b8 <main+0xe8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
cmp    $0x2,%edi
jne    1207 <main+0x27>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
cmp    $0x4,%eax
jb     122a <main+0x4a>
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r15d
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x1ed3,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xd98(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    0x8(%rbx),%r12
lea    0x10(%rsp),%rbp
lea    0x30(%rsp),%rbx
lea    0xd7d(%rip),%r14
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x51eb851f,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edx
mov    %rbp,%rdi
lea    0xd3d(%rip),%rsi
call   10d0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
lea    0xd26(%rip),%rsi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10c0 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r13,%r8
mov    $0x10,%r9d
call   1090 <sendto@plt>
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   10e0 <sleep@plt>
jmp    12a0 <main+0xc0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [107 x i8] c"\0A Use: ./client <id> \0A id belongs to [0,N_PROCESSUS] \0A N_PROCESSUS is a #define in server.c and client.c \0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [3 x i8] c"%s\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 [1024 x i8]
%12 = alloca [32 x i8]
%13 = alloca i8*
%14 = alloca %struct.sockaddr_in
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %30, label %18
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp sgt i32 %22, 3
br i1 %23, label %30, label %24
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24, %18, %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str, i64 0, i64 0))
ret i32 1
32: ; preds = %24
store i32 7891, i32* %7
%33 = load i32, i32* @PF_INET
%34 = load i32, i32* @SOCK_DGRAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %6
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 3
store i32 %36, i32* %37
%38 = load i32, i32* %7
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %39, i32* %40
%41 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @memset(i32 %45, i8 signext 0, i32 4)
store i32 16, i32* %15
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
store i8* %49, i8** %13
br label %50
50: ; preds = %32, %50
%51 = call i32 (...) @rand()
%52 = srem i32 %51, 100
store i32 %52, i32* %9
%53 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%54 = load i32, i32* %9
%55 = call i32 @sprintf(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%57 = load i8*, i8** %13
%58 = call i32 @strcpy(i8* %56, i8* %57)
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%60 = call i32 @strcat(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%63 = call i32 @strcat(i8* %61, i8* %62)
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
%69 = load i32, i32* %6
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%71 = load i32, i32* %8
%72 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%73 = load i32, i32* %15
%74 = call i32 @sendto(i32 %69, i8* %70, i32 %71, i32 0, %struct.sockaddr* %72, i32 %73)
%75 = call i32 (...) @rand()
%76 = srem i32 %75, 10
store i32 %76, i32* %10
%77 = load i32, i32* %10
%78 = call i32 @sleep(i32 %77)
br label %50
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [3 x i8] c"%s\00"
@str = [106 x i8] c"\0A Use: ./client <id> \0A id belongs to [0,N_PROCESSUS] \0A N_PROCESSUS is a #define in server.c and client.c \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [32 x i8]
%5 = alloca %struct.sockaddr_in
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp ugt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %7, %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([106 x i8], [106 x i8]* @str, i64 0, i64 0))
ret i32 1
14: ; preds = %7
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%17 = bitcast %struct.sockaddr_in* %5 to i8*
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 3
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 7891)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%28 = load i8*, i8** %8
%29 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %30
30: ; preds = %30, %14
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 100
%33 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = call i32 @strcpy(i8* %15, i8* %28)
%35 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @strcat(i8* %15, i8* %16)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%38 = call i32 @strlen(i8* %15)
%39 = add nsw i32 %38, 1
%40 = call i32 @sendto(i32 %20, i8* %15, i32 %39, i32 0, %struct.sockaddr* %29, i32 16)
%41 = call i32 (...) @rand()
%42 = srem i32 %41, 10
%43 = call i32 @sleep(i32 %42)
br label %30
}