#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;
  void *sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ clnt_addr;
typedef int /*<<< orphan*/ buf_rcv;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
void *AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fork();
int listen(int, int);
int /*<<< orphan*/ mktemp(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strlen(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
PM_main(int argc, char *argv[]) {
  int sockfd, nsockfd;
  int saddrlen, caddrlen, max_caddrlen;
  int pid;
  struct sockaddr_un serv_addr, clnt_addr;
  char buf[1024] =
      "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
       buf_rcv[1024];
  switch (pid = fork()) {
  case -1:
    perror("Error call fork()");
    return (1);
    break;
  case 0:
    bzero((char *)&serv_addr, sizeof(serv_addr));
    serv_addr.sun_family = AF_UNIX;
    strcpy(serv_addr.sun_path, "/tmp/echo.server");
    saddrlen = sizeof(serv_addr.sun_family) + strlen(serv_addr.sun_path);
    if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
      perror("client: socket open failure");
      return (1);
    }
    if (bind(sockfd, (struct sockaddr *)&serv_addr, saddrlen) < 0) {
      printf("server bind failure:\n");
      fflush(NULL);
      return (1);
    }
    if (listen(sockfd, 5) == -1) {
      perror("Error call listen()");
      return (1);
    }
    max_caddrlen = sizeof(clnt_addr);
    caddrlen = max_caddrlen;
    if ((nsockfd = accept(sockfd, (struct sockaddr *)&clnt_addr, &caddrlen)) ==
        -1) {
      perror("Error call accept()");
      return (1);
    }
    close(sockfd);
    while (read(nsockfd, buf, sizeof(buf)) != 0) {
      write(nsockfd, buf, sizeof(buf));
    }
    close(nsockfd);
    unlink("/tmp/echo.server");
    return (0);
    break;
  default:
    bzero((char *)&serv_addr, sizeof(serv_addr));
    serv_addr.sun_family = AF_UNIX;
    strcpy(serv_addr.sun_path, "/tmp/echo.server");
    saddrlen = sizeof(serv_addr.sun_family) + strlen(serv_addr.sun_path);
    if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
      perror("client: socket open failure");
      return (1);
    }
    sleep(3);
    if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
      perror("error connect to server");
      return (1);
    }
    bzero((char *)&clnt_addr, sizeof(clnt_addr));
    clnt_addr.sun_family = AF_UNIX;
    strcpy(clnt_addr.sun_path, "/tmp/clnt.XXXX");
    mktemp(clnt_addr.sun_path);
    caddrlen = sizeof(clnt_addr.sun_family) + strlen(clnt_addr.sun_path);
    if (bind(sockfd, (struct sockaddr *)&clnt_addr, caddrlen) < 0) {
      perror("error call bind()");
      return (1);
    }
    if ((write(sockfd, buf, sizeof(buf))) < 0) {
      perror("Error write to socket");
      return (1);
    }
    if (read(sockfd, buf_rcv, sizeof(buf_rcv)) < 0) {
      perror("Error read from socket");
      return (1);
    }
    close(sockfd);
    if (strcmp(buf_rcv, buf) == 0)
      return (0);
    else
      return (1);
    break;
  }
}


x86 assembly (clang, -O0):
<PM_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xda7(%rip),%rsi
lea    -0x450(%rbp),%rdi
mov    $0x400,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1140 <fork@plt>
mov    %eax,-0x28(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x854(%rbp)
sub    $0xffffffff,%eax
je     129d <PM_main+0x5d>
jmp    128a <PM_main+0x4a>
mov    -0x854(%rbp),%eax
test   %eax,%eax
je     12b5 <PM_main+0x75>
jmp    1435 <PM_main+0x1f5>
lea    0x115c(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
lea    -0x38(%rbp),%rdi
mov    $0x10,%esi
call   1100 <bzero@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%edi
lea    0x1137(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%edi
call   1060 <strlen@plt>
cltq
add    $0x8,%rax
mov    %eax,-0x1c(%rbp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%rdi
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    132f <PM_main+0xef>
lea    0x1105(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10e0 <bind@plt>
cmp    $0x0,%eax
jge    1368 <PM_main+0x128>
lea    0x10f1(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <fflush@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1396 <PM_main+0x156>
lea    0x10d0(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
movl   $0x10,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    13d7 <PM_main+0x197>
lea    0x10a3(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
cmp    $0x0,%eax
je     1415 <PM_main+0x1d5>
mov    -0x18(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1050 <write@plt>
jmp    13df <PM_main+0x19f>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
lea    0xfee(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
lea    -0x38(%rbp),%rdi
mov    $0x10,%esi
call   1100 <bzero@plt>
mov    0x2b9e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%edi
lea    0xfb7(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%edi
call   1060 <strlen@plt>
cltq
add    $0x8,%rax
mov    %eax,-0x1c(%rbp)
mov    0x2b70(%rip),%rax
mov    (%rax),%rdi
mov    0x2b56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    14af <PM_main+0x26f>
lea    0xf85(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
mov    $0x3,%edi
call   1130 <sleep@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1120 <connect@plt>
cmp    $0x0,%eax
jge    14eb <PM_main+0x2ab>
lea    0xfa3(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
lea    -0x48(%rbp),%rdi
mov    $0x10,%esi
call   1100 <bzero@plt>
mov    0x2ae8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%edi
lea    0xf84(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x48(%rbp),%edi
call   1160 <mktemp@plt>
mov    -0x48(%rbp),%edi
call   1060 <strlen@plt>
cltq
add    $0x8,%rax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   10e0 <bind@plt>
cmp    $0x0,%eax
jge    155f <PM_main+0x31f>
lea    0xf56(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
mov    -0x14(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1050 <write@plt>
cmp    $0x0,%eax
jge    1594 <PM_main+0x354>
lea    0xf33(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
mov    -0x14(%rbp),%edi
lea    -0x850(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
cmp    $0x0,%eax
jge    15c9 <PM_main+0x389>
lea    0xf14(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
lea    -0x850(%rbp),%rdi
lea    -0x450(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    15f9 <PM_main+0x3b9>
movl   $0x0,-0x4(%rbp)
jmp    1600 <PM_main+0x3c0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PM_main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x830,%rsp
lea    0xdae(%rip),%rsi
lea    0x30(%rsp),%rdi
mov    $0x400,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     13a2 <PM_main+0x162>
cmp    $0xffffffff,%eax
je     14c7 <PM_main+0x287>
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1100 <bzero@plt>
mov    0x2d59(%rip),%rbp
mov    0x0(%rbp),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%ebx
lea    0x116f(%rip),%rsi
mov    %ebx,%edi
call   1040 <strcpy@plt>
mov    %ebx,%edi
call   1070 <strlen@plt>
mov    0x0(%rbp),%rdi
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     14be <PM_main+0x27e>
mov    %eax,%ebx
mov    $0x3,%edi
call   1130 <sleep@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1120 <connect@plt>
test   %eax,%eax
js     14d0 <PM_main+0x290>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1100 <bzero@plt>
mov    0x0(%rbp),%rax
mov    %rax,0x28(%rsp)
mov    0x20(%rsp),%ebp
lea    0x1167(%rip),%rsi
mov    %ebp,%edi
call   1040 <strcpy@plt>
mov    %ebp,%edi
call   1160 <mktemp@plt>
mov    %ebp,%edi
call   1070 <strlen@plt>
lea    0x8(%rax),%edx
mov    %edx,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
call   10e0 <bind@plt>
test   %eax,%eax
js     14d9 <PM_main+0x299>
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1060 <write@plt>
test   %eax,%eax
js     14e2 <PM_main+0x2a2>
lea    0x430(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
js     14eb <PM_main+0x2ab>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0x430(%rsp),%rdi
lea    0x30(%rsp),%rsi
call   10a0 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
jmp    150e <PM_main+0x2ce>
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1100 <bzero@plt>
mov    0x2c30(%rip),%r14
mov    (%r14),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%ebx
lea    0x1047(%rip),%rsi
mov    %ebx,%edi
call   1040 <strcpy@plt>
mov    %ebx,%edi
call   1070 <strlen@plt>
mov    %eax,%ebp
mov    (%r14),%rdi
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     14be <PM_main+0x27e>
mov    %eax,%ebx
add    $0x8,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    %ebp,%edx
call   10e0 <bind@plt>
test   %eax,%eax
js     14a9 <PM_main+0x269>
mov    %ebx,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
je     14f4 <PM_main+0x2b4>
movl   $0x10,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     14fd <PM_main+0x2bd>
mov    %eax,%ebp
mov    %ebx,%edi
call   1080 <close@plt>
lea    0x30(%rsp),%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
je     1492 <PM_main+0x252>
lea    0x30(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
jne    1470 <PM_main+0x230>
mov    %ebp,%edi
call   1080 <close@plt>
lea    0xf72(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
jmp    150e <PM_main+0x2ce>
lea    0x101d(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10c0 <fflush@plt>
jmp    1509 <PM_main+0x2c9>
lea    0xf5e(%rip),%rdi
jmp    1504 <PM_main+0x2c4>
lea    0xf32(%rip),%rdi
jmp    1504 <PM_main+0x2c4>
lea    0xf90(%rip),%rdi
jmp    1504 <PM_main+0x2c4>
lea    0xfae(%rip),%rdi
jmp    1504 <PM_main+0x2c4>
lea    0xfb7(%rip),%rdi
jmp    1504 <PM_main+0x2c4>
lea    0xfc4(%rip),%rdi
jmp    1504 <PM_main+0x2c4>
lea    0xf44(%rip),%rdi
jmp    1504 <PM_main+0x2c4>
lea    0xf4f(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%eax
add    $0x830,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@__const.PM_main.buf = [1024 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [18 x i8] c"Error call fork()\00"
@AF_UNIX = global i8* null
@.str.1 = [17 x i8] c"/tmp/echo.server\00"
@SOCK_STREAM = global i32 0
@.str.2 = [28 x i8] c"client: socket open failure\00"
@.str.3 = [22 x i8] c"server bind failure:\0A\00"
@.str.4 = [20 x i8] c"Error call listen()\00"
@.str.5 = [20 x i8] c"Error call accept()\00"
@.str.6 = [24 x i8] c"error connect to server\00"
@.str.7 = [15 x i8] c"/tmp/clnt.XXXX\00"
@.str.8 = [18 x i8] c"error call bind()\00"
@.str.9 = [22 x i8] c"Error write to socket\00"
@.str.10 = [23 x i8] c"Error read from socket\00"
define i32 @PM_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
%14 = alloca [1024 x i8]
%15 = alloca [1024 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [1024 x i8]* %14 to i8*
%17 = call i32 (...) @fork()
store i32 %17, i32* %11
switch i32 %17, label %79 [
i32 -1, label %18
i32 0, label %20
]
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %154
20: ; preds = %2
%21 = bitcast %struct.sockaddr_un* %12 to i8*
%22 = call i32 @bzero(i8* %21, i32 16)
%23 = load i8*, i8** @AF_UNIX
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 1
store i8* %23, i8** %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @strcpy(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @strlen(i32 %29)
%31 = sext i32 %30 to i64
%32 = add i64 8, %31
%33 = trunc i64 %32 to i32
store i32 %33, i32* %8
%34 = load i8*, i8** @AF_UNIX
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i8* %34, i32 %35, i32 0)
store i32 %36, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %20
%39 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %154
40: ; preds = %20
%41 = load i32, i32* %6
%42 = bitcast %struct.sockaddr_un* %12 to %struct.sockaddr*
%43 = load i32, i32* %8
%44 = call i32 @bind(i32 %41, %struct.sockaddr* %42, i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @fflush(i32* null)
store i32 1, i32* %3
br label %154
49: ; preds = %40
%50 = load i32, i32* %6
%51 = call i32 @listen(i32 %50, i32 5)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %154
55: ; preds = %49
store i32 16, i32* %10
%56 = load i32, i32* %10
store i32 %56, i32* %9
%57 = load i32, i32* %6
%58 = bitcast %struct.sockaddr_un* %13 to %struct.sockaddr*
%59 = call i32 @accept(i32 %57, %struct.sockaddr* %58, i32* %9)
store i32 %59, i32* %7
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %154
63: ; preds = %55
%64 = load i32, i32* %6
%65 = call i32 @close(i32 %64)
br label %66
66: ; preds = %71, %63
%67 = load i32, i32* %7
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%69 = call i32 @read(i32 %67, i8* %68, i32 1024)
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %66
%72 = load i32, i32* %7
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%74 = call i32 @write(i32 %72, i8* %73, i32 1024)
br label %66
75: ; preds = %66
%76 = load i32, i32* %7
%77 = call i32 @close(i32 %76)
%78 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %154
79: ; preds = %2
%80 = bitcast %struct.sockaddr_un* %12 to i8*
%81 = call i32 @bzero(i8* %80, i32 16)
%82 = load i8*, i8** @AF_UNIX
%83 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 1
store i8* %82, i8** %83
%84 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%85 = load i32, i32* %84
%86 = call i32 @strcpy(i32 %85, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%87 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%88 = load i32, i32* %87
%89 = call i32 @strlen(i32 %88)
%90 = sext i32 %89 to i64
%91 = add i64 8, %90
%92 = trunc i64 %91 to i32
store i32 %92, i32* %8
%93 = load i8*, i8** @AF_UNIX
%94 = load i32, i32* @SOCK_STREAM
%95 = call i32 @socket(i8* %93, i32 %94, i32 0)
store i32 %95, i32* %6
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %79
%98 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %154
99: ; preds = %79
%100 = call i32 @sleep(i32 3)
%101 = load i32, i32* %6
%102 = bitcast %struct.sockaddr_un* %12 to %struct.sockaddr*
%103 = call i32 @connect(i32 %101, %struct.sockaddr* %102, i32 16)
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %99
%106 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %154
107: ; preds = %99
%108 = bitcast %struct.sockaddr_un* %13 to i8*
%109 = call i32 @bzero(i8* %108, i32 16)
%110 = load i8*, i8** @AF_UNIX
%111 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %13, i32 0, i32 1
store i8* %110, i8** %111
%112 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %13, i32 0, i32 0
%113 = load i32, i32* %112
%114 = call i32 @strcpy(i32 %113, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%115 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %13, i32 0, i32 0
%116 = load i32, i32* %115
%117 = call i32 @mktemp(i32 %116)
%118 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %13, i32 0, i32 0
%119 = load i32, i32* %118
%120 = call i32 @strlen(i32 %119)
%121 = sext i32 %120 to i64
%122 = add i64 8, %121
%123 = trunc i64 %122 to i32
store i32 %123, i32* %9
%124 = load i32, i32* %6
%125 = bitcast %struct.sockaddr_un* %13 to %struct.sockaddr*
%126 = load i32, i32* %9
%127 = call i32 @bind(i32 %124, %struct.sockaddr* %125, i32 %126)
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %131
129: ; preds = %107
%130 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %154
131: ; preds = %107
%132 = load i32, i32* %6
%133 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%134 = call i32 @write(i32 %132, i8* %133, i32 1024)
%135 = icmp slt i32 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %131
%137 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %154
138: ; preds = %131
%139 = load i32, i32* %6
%140 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%141 = call i32 @read(i32 %139, i8* %140, i32 1024)
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %145
143: ; preds = %138
%144 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %154
145: ; preds = %138
%146 = load i32, i32* %6
%147 = call i32 @close(i32 %146)
%148 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%149 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%150 = call i32 @strcmp(i8* %148, i8* %149)
%151 = icmp eq i32 %150, 0
br i1 %151, label %152, label %153
152: ; preds = %145
store i32 0, i32* %3
br label %154
153: ; preds = %145
store i32 1, i32* %3
br label %154
154: ; preds = %153, %152, %143, %136, %129, %105, %97, %75, %61, %53, %46, %38, %18
%155 = load i32, i32* %3
ret i32 %155
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@__const.PM_main.buf = [1024 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [18 x i8] c"Error call fork()\00"
@AF_UNIX = global i8* null
@.str.1 = [17 x i8] c"/tmp/echo.server\00"
@SOCK_STREAM = global i32 0
@.str.2 = [28 x i8] c"client: socket open failure\00"
@.str.4 = [20 x i8] c"Error call listen()\00"
@.str.5 = [20 x i8] c"Error call accept()\00"
@.str.6 = [24 x i8] c"error connect to server\00"
@.str.7 = [15 x i8] c"/tmp/clnt.XXXX\00"
@.str.8 = [18 x i8] c"error call bind()\00"
@.str.9 = [22 x i8] c"Error write to socket\00"
@.str.10 = [23 x i8] c"Error read from socket\00"
@str = [21 x i8] c"server bind failure:\00"
define i32 @PM_main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca %struct.sockaddr_un
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = bitcast i32* %3 to i8*
%9 = bitcast %struct.sockaddr_un* %4 to i8*
%10 = bitcast %struct.sockaddr_un* %5 to i8*
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = tail call i32 (...) @fork()
switch i32 %13, label %60 [
i32 -1, label %14
i32 0, label %16
]
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %111
16: ; preds = %2
%17 = call i32 @bzero(i8* %9, i32 16)
%18 = load i8*, i8** @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i8* %18, i8** %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i32 @strcpy(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @strlen(i32 %21)
%24 = load i8*, i8** @AF_UNIX
%25 = load i32, i32* @SOCK_STREAM
%26 = tail call i32 @socket(i8* %24, i32 %25, i32 0)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %111
30: ; preds = %16
%31 = add i32 %23, 8
%32 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%33 = call i32 @bind(i32 %26, %struct.sockaddr* %32, i32 %31)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%37 = call i32 @fflush(i32* null)
br label %111
38: ; preds = %30
%39 = call i32 @listen(i32 %26, i32 5)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %111
43: ; preds = %38
store i32 16, i32* %3
%44 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%45 = call i32 @accept(i32 %26, %struct.sockaddr* %44, i32* %3)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %111
49: ; preds = %43
%50 = call i32 @close(i32 %26)
%51 = call i32 @read(i32 %45, i8* %11, i32 1024)
%52 = icmp eq i32 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %49, %53
%54 = call i32 @write(i32 %45, i8* %11, i32 1024)
%55 = call i32 @read(i32 %45, i8* %11, i32 1024)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %53
57: ; preds = %53, %49
%58 = call i32 @close(i32 %45)
%59 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %111
60: ; preds = %2
%61 = call i32 @bzero(i8* %9, i32 16)
%62 = load i8*, i8** @AF_UNIX
%63 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i8* %62, i8** %63
%64 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
%65 = load i32, i32* %64
%66 = tail call i32 @strcpy(i32 %65, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%67 = tail call i32 @strlen(i32 %65)
%68 = load i8*, i8** @AF_UNIX
%69 = load i32, i32* @SOCK_STREAM
%70 = tail call i32 @socket(i8* %68, i32 %69, i32 0)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %60
%73 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %111
74: ; preds = %60
%75 = tail call i32 @sleep(i32 3)
%76 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%77 = call i32 @connect(i32 %70, %struct.sockaddr* %76, i32 16)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %111
81: ; preds = %74
%82 = call i32 @bzero(i8* %10, i32 16)
%83 = load i8*, i8** @AF_UNIX
%84 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i8* %83, i8** %84
%85 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 0
%86 = load i32, i32* %85
%87 = call i32 @strcpy(i32 %86, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%88 = call i32 @mktemp(i32 %86)
%89 = call i32 @strlen(i32 %86)
%90 = add i32 %89, 8
store i32 %90, i32* %3
%91 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%92 = call i32 @bind(i32 %70, %struct.sockaddr* %91, i32 %90)
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %81
%95 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %111
96: ; preds = %81
%97 = call i32 @write(i32 %70, i8* %11, i32 1024)
%98 = icmp slt i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %96
%100 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %111
101: ; preds = %96
%102 = call i32 @read(i32 %70, i8* %12, i32 1024)
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %101
%105 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %111
106: ; preds = %101
%107 = call i32 @close(i32 %70)
%108 = call i32 @strcmp(i8* %12, i8* %11)
%109 = icmp ne i32 %108, 0
%110 = zext i1 %109 to i32
br label %111
111: ; preds = %106, %104, %99, %94, %79, %72, %57, %47, %41, %35, %28, %14
%112 = phi i32 [ 1, %72 ], [ 1, %79 ], [ 1, %94 ], [ 1, %99 ], [ 1, %104 ], [ 1, %28 ], [ 1, %35 ], [ 1, %41 ], [ 1, %47 ], [ 0, %57 ], [ 1, %14 ], [ %110, %106 ]
ret i32 %112
}