#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 */
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ s_un;
typedef int pid_t;
typedef int /*<<< orphan*/ from;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_SEQPACKET;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ communication(struct sockaddr_un, int);
int /*<<< orphan*/ exit(int);
int fork();
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main(int argc, char **argv) {
  int s, ns, r, port;
  pid_t pid;
  socklen_t fromlen;
  struct sockaddr_un s_un, from;
  signal(SIGCHLD, SIG_IGN);
  if (argc != 2) {
    printf("Usage : %s  port_serveur\n", argv[0]);
    exit(1);
  }
  port = atoi(argv[1]);
  if (port < 5000) {
    printf("donnez un numero de port superieur a 5000\n");
    exit(1);
  }
  memset(&s_un, 0, sizeof(s_un));
  s_un.sun_family = AF_UNIX;
  strcpy(s_un.sun_path, "server_socket");
  s = socket(AF_UNIX, SOCK_SEQPACKET, 0);
  if (s == -1) {
    perror("socket");
    exit(2);
  }
  r = bind(s, (struct sockaddr *)&s_un, sizeof(s_un));
  if (r == -1) {
    perror("bind");
    exit(3);
  }
  if (listen(s, 5) < 0) {
    perror("listen");
    exit(4);
  }
  fromlen = sizeof(from);
  for (;;) {
    ns = accept(s, (struct sockaddr *)&from, &fromlen);
    if (ns == -1) {
      perror("accept");
      exit(1);
    }
    pid = fork();
    if (pid == -1) {
      perror("Error forking!");
      exit(5);
    }
    if (pid == 0) {
      communication(from, ns);
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
cmpl   $0x2,-0x8(%rbp)
je     1226 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1388,-0x20(%rbp)
jge    125b <main+0x8b>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%edi
lea    0xdc4(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12c2 <main+0xf2>
lea    0xd99(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1090 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12f6 <main+0x126>
lea    0xd6c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    1323 <main+0x153>
lea    0xd44(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%edi
call   10d0 <exit@plt>
movl   $0x8,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    135d <main+0x18d>
lea    0xd11(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1387 <main+0x1b7>
lea    0xcee(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x5,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
jne    13a4 <main+0x1d4>
mov    -0x18(%rbp),%esi
mov    -0x38(%rbp),%rdi
call   1060 <communication@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    132a <main+0x15a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
cmp    $0x2,%ebp
jne    1231 <main+0x51>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
cmp    $0x1387,%eax
jg     124c <main+0x6c>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    (%rbx),%rsi
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2d86(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
mov    (%rsp),%edi
lea    0xda8(%rip),%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
jne    12a4 <main+0xc4>
lea    0xd8c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12d0 <main+0xf0>
lea    0xd67(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %rax,%rax
jns    12f7 <main+0x117>
lea    0xd45(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x4,%edi
call   10e0 <exit@plt>
movl   $0x8,0xc(%rsp)
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10c0 <accept@plt>
cmp    $0xffffffff,%eax
je     134a <main+0x16a>
mov    %eax,%ebp
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1360 <main+0x180>
cmp    $0xffffffff,%eax
jne    1310 <main+0x130>
lea    0xd00(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x5,%edi
call   10e0 <exit@plt>
lea    0xce3(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x10(%rsp),%rdi
mov    %ebp,%esi
call   1070 <communication@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [26 x i8] c"Usage : %s port_serveur\0A\00"
@.str.1 = [43 x i8] c"donnez un numero de port superieur a 5000\0A\00"
@AF_UNIX = global i32 0
@.str.2 = [14 x i8] c"server_socket\00"
@SOCK_SEQPACKET = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [5 x i8] c"bind\00"
@.str.5 = [7 x i8] c"listen\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [15 x i8] c"Error forking!\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 %struct.sockaddr_un
%13 = alloca %struct.sockaddr_un
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @SIGCHLD
%15 = load i32, i32* @SIG_IGN
%16 = call i32 @signal(i32 %14, i32 %15)
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 5000
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %25
%36 = call i32 @memset(%struct.sockaddr_un* %12, i32 0, i32 8)
%37 = load i32, i32* @AF_UNIX
%38 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 1
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @strcpy(i32 %40, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @AF_UNIX
%43 = load i32, i32* @SOCK_SEQPACKET
%44 = call i32 @socket(i32 %42, i32 %43, i32 0)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %35
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 2)
unreachable
50: ; preds = %35
%51 = load i32, i32* %6
%52 = bitcast %struct.sockaddr_un* %12 to %struct.sockaddr*
%53 = call i32 @bind(i32 %51, %struct.sockaddr* %52, i32 8)
store i32 %53, i32* %8
%54 = load i32, i32* %8
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @exit(i32 3)
unreachable
59: ; preds = %50
%60 = load i32, i32* %6
%61 = call i64 @listen(i32 %60, i32 5)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%65 = call i32 @exit(i32 4)
unreachable
66: ; preds = %59
store i32 8, i32* %11
br label %67
67: ; preds = %92, %66
%68 = load i32, i32* %6
%69 = bitcast %struct.sockaddr_un* %13 to %struct.sockaddr*
%70 = call i32 @accept(i32 %68, %struct.sockaddr* %69, i32* %11)
store i32 %70, i32* %7
%71 = load i32, i32* %7
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %67
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %67
%77 = call i32 (...) @fork()
store i32 %77, i32* %10
%78 = load i32, i32* %10
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%82 = call i32 @exit(i32 5)
unreachable
83: ; preds = %76
%84 = load i32, i32* %10
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %92
86: ; preds = %83
%87 = load i32, i32* %7
%88 = bitcast %struct.sockaddr_un* %13 to i64*
%89 = load i64, i64* %88
%90 = call i32 @communication(i64 %89, i32 %87)
%91 = call i32 @exit(i32 0)
unreachable
92: ; preds = %83
br label %67
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [26 x i8] c"Usage : %s port_serveur\0A\00"
@AF_UNIX = global i32 0
@.str.2 = [14 x i8] c"server_socket\00"
@SOCK_SEQPACKET = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [5 x i8] c"bind\00"
@.str.5 = [7 x i8] c"listen\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [15 x i8] c"Error forking!\00"
@str = [42 x i8] c"donnez un numero de port superieur a 5000\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_un* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = load i32, i32* @SIGCHLD
%10 = load i32, i32* @SIG_IGN
%11 = tail call i32 @signal(i32 %9, i32 %10)
%12 = icmp eq i32 %0, 2
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp slt i32 %20, 5000
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = call i32 @memset(%struct.sockaddr_un* %4, i32 0, i32 8)
%27 = load i32, i32* @AF_UNIX
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @strcpy(i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @AF_UNIX
%33 = load i32, i32* @SOCK_SEQPACKET
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 2)
unreachable
39: ; preds = %25
%40 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%41 = call i32 @bind(i32 %34, %struct.sockaddr* %40, i32 8)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 @exit(i32 3)
unreachable
46: ; preds = %39
%47 = call i64 @listen(i32 %34, i32 5)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 4)
unreachable
52: ; preds = %46
store i32 8, i32* %3
%53 = bitcast i64* %5 to %struct.sockaddr*
br label %54
54: ; preds = %60, %52
%55 = call i32 @accept(i32 %34, %struct.sockaddr* %53, i32* %3)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %54
%61 = call i32 (...) @fork()
switch i32 %61, label %54 [
i32 -1, label %62
i32 0, label %65
]
62: ; preds = %60
%63 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%64 = call i32 @exit(i32 5)
unreachable
65: ; preds = %60
%66 = load i64, i64* %5
%67 = call i32 @communication(i64 %66, i32 %55)
%68 = call i32 @exit(i32 0)
unreachable
}