#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 size_t ssize_t;
typedef int /*<<< orphan*/ addrlocal;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_SEQPACKET;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
size_t write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sfd, c;
  struct sockaddr_un addrlocal;
  char buf[512], *pt;
  ssize_t nread, nwrite;
  if (argc != 2) {
    printf("Usage: %s file path\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  sfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
  if (sfd < 0) {
    perror("socket");
    exit(0);
  }
  memset(&addrlocal, 0, sizeof(struct sockaddr_un));
  addrlocal.sun_family = AF_UNIX;
  snprintf(addrlocal.sun_path, 108, argv[1]);
  c = connect(sfd, (struct sockaddr *)&addrlocal, sizeof(addrlocal));
  if (c < 0) {
    perror("bind");
    exit(0);
  }
  for (;;) {
    nread = read(sfd, buf, 512);
    if (nread == 0) {
      printf("Connexion rompue\n");
      exit(EXIT_SUCCESS);
    } else if (nread < 0) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    buf[nread] = '\0';
    printf("Message recu '%s'", buf);
    pt = fgets(buf, 512, stdin);
    if (pt == NULL) {
      printf("Sortie du client\n");
      exit(EXIT_SUCCESS);
    }
    nwrite = write(sfd, buf, strlen(buf));
    if (nwrite < 0) {
      perror("write");
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    122f <main+0x7f>
lea    0xdf2(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x6c,%esi
call   1060 <snprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   10c0 <connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1291 <main+0xe1>
lea    0xd97(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    1296 <main+0xe6>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jne    12db <main+0x12b>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x230(%rbp)
jae    1303 <main+0x153>
lea    0xd43(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1308 <main+0x158>
mov    -0x230(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x220(%rbp),%rdi
mov    0x2ca6(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1090 <fgets@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    1377 <main+0x1c7>
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x244(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x240(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x244(%rbp),%edi
mov    -0x240(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jae    13dd <main+0x22d>
lea    0xc92(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2bfa(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1296 <main+0xe6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11fc <main+0x3c>
mov    0x2e0c(%rip),%r15
mov    (%r15),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
jns    121b <main+0x5b>
lea    0xe1b(%rip),%rdi
jmp    1264 <main+0xa4>
mov    (%rbx),%rsi
lea    0xdfa(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    0x8(%rbx),%rdx
mov    $0x6c,%esi
call   1070 <snprintf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10d0 <connect@plt>
test   %eax,%eax
jns    1270 <main+0xb0>
lea    0xdb8(%rip),%rdi
call   10b0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x200,%edx
call   1090 <read@plt>
test   %rax,%rax
je     12ef <main+0x12f>
lea    0xd94(%rip),%r14
lea    0x10(%rsp),%rbx
mov    0x2d47(%rip),%r15
nopl   0x0(%rax)
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x200,%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     12f8 <main+0x138>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
test   %rax,%rax
jne    12a0 <main+0xe0>
lea    0xd4e(%rip),%rdi
jmp    12ff <main+0x13f>
lea    0xd34(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s file path\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNIX = global i32 0
@SOCK_SEQPACKET = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [18 x i8] c"Connexion rompue\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [18 x i8] c"Message recu '%s'\00"
@stdin = global i32 0
@.str.6 = [18 x i8] c"Sortie du client\0A\00"
@.str.7 = [6 x i8] c"write\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 %struct.sockaddr_un
%9 = alloca [512 x i8]
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* @AF_UNIX
%24 = load i32, i32* @SOCK_SEQPACKET
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %22
%32 = call i32 @memset(%struct.sockaddr_un* %8, i32 0, i32 8)
%33 = load i32, i32* @AF_UNIX
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @snprintf(i32 %36, i32 108, i8* %39)
%41 = load i32, i32* %6
%42 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%43 = call i32 @connect(i32 %41, %struct.sockaddr* %42, i32 8)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %31
%47 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %31
br label %50
50: ; preds = %94, %49
%51 = load i32, i32* %6
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%53 = call i64 @read(i32 %51, i8* %52, i32 512)
store i64 %53, i64* %11
%54 = load i64, i64* %11
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @EXIT_SUCCESS
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %50
%61 = load i64, i64* %11
%62 = icmp ult i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %60
br label %68
68: ; preds = %67
%69 = load i64, i64* %11
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %69
store i8 0, i8* %70
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %71)
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%74 = load i32, i32* @stdin
%75 = call i8* @fgets(i8* %73, i32 512, i32 %74)
store i8* %75, i8** %10
%76 = load i8*, i8** %10
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %82
78: ; preds = %68
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%80 = load i32, i32* @EXIT_SUCCESS
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %68
%83 = load i32, i32* %6
%84 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%85 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%86 = call i32 @strlen(i8* %85)
%87 = call i64 @write(i32 %83, i8* %84, i32 %86)
store i64 %87, i64* %12
%88 = load i64, i64* %12
%89 = icmp ult i64 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %82
%91 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%92 = load i32, i32* @EXIT_FAILURE
%93 = call i32 @exit(i32 %92)
unreachable
94: ; preds = %82
br label %50
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s file path\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNIX = global i32 0
@SOCK_SEQPACKET = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [5 x i8] c"bind\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [18 x i8] c"Message recu '%s'\00"
@stdin = global i32 0
@str = [17 x i8] c"Sortie du client\00"
@str.8 = [17 x i8] c"Connexion rompue\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [512 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_SEQPACKET
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %13
%22 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%23 = load i32, i32* @AF_UNIX
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @snprintf(i32 %26, i32 108, i8* %28)
%30 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%31 = call i32 @connect(i32 %16, %struct.sockaddr* %30, i32 8)
%32 = icmp slt i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %21
%34 = call i64 @read(i32 %16, i8* %6, i32 512)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %43
36: ; preds = %21
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %54, %33
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %33, %54
%44 = phi i64 [ %57, %54 ], [ %34, %33 ]
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %44
store i8 0, i8* %45
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%47 = load i32, i32* @stdin
%48 = call i8* @fgets(i8* %6, i32 512, i32 %47)
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %54
50: ; preds = %43
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%52 = load i32, i32* @EXIT_SUCCESS
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %43
%55 = call i32 @strlen(i8* %6)
%56 = call i64 @write(i32 %16, i8* %6, i32 %55)
%57 = call i64 @read(i32 %16, i8* %6, i32 512)
%58 = icmp eq i64 %57, 0
br i1 %58, label %39, label %43
}