#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 /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ remote;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, void const *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sock, sock2;
  struct sockaddr_un local, remote;
  int len;
  char *path;
  if (argc == 1) {
    path = "/tmp/db_sanitize.sock";
  } else {
    path = argv[1];
  }
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
  local.sun_family = AF_UNIX;
  strcpy(local.sun_path, path);
  unlink(local.sun_path);
  len = sizeof(struct sockaddr_un);
  if (bind(sock, (struct sockaddr *)&local, len) == -1) {
    perror("bind");
    exit(1);
  }
  if (listen(sock, 32) == -1) {
    perror("listen");
    exit(1);
  }
  for (;;) {
    int done, n, t;
    char str[2048] = {0};
    printf("Waiting for a connection...\n");
    t = sizeof(remote);
    if ((sock2 = accept(sock, (struct sockaddr *)&remote, (socklen_t *)&t)) ==
        -1) {
      perror("accept");
      exit(1);
    }
    printf("Connected.\n");
    done = 0;
    do {
      n = recv(sock2, str, 2048, 0);
      if (n == 0)
        done = 1;
      else if (n < 0)
        perror("recv");
      if (!done) {
        printf("got : '%s'", str);
        if (send(sock2, (const void *)&str, 2048, 0) < 0) {
          perror("send");
          done = 1;
        }
      }
    } while (!done);
    close(sock2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1203 <main+0x33>
lea    0xe06(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%edi
call   1040 <unlink@plt>
movl   $0x8,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0xb0>
lea    0xda5(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x20,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12ac <main+0xdc>
lea    0xd7e(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    12b1 <main+0xe1>
lea    -0x850(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1080 <memset@plt>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x8,-0x44(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    130b <main+0x13b>
lea    0xd43(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x850(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    134f <main+0x17f>
movl   $0x1,-0x3c(%rbp)
jmp    136a <main+0x19a>
cmpl   $0x0,-0x40(%rbp)
jge    1365 <main+0x195>
lea    0xcf2(%rip),%rdi
call   10c0 <perror@plt>
jmp    136a <main+0x19a>
cmpl   $0x0,-0x3c(%rbp)
jne    13c1 <main+0x1f1>
lea    -0x850(%rbp),%rsi
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x850(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x0,%rax
jge    13bc <main+0x1ec>
lea    0xcb2(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x3c(%rbp)
jmp    13c1 <main+0x1f1>
jmp    13c6 <main+0x1f6>
cmpl   $0x0,-0x3c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1320 <main+0x150>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    12b1 <main+0xe1>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
cmp    $0x1,%edi
jne    11ff <main+0x1f>
lea    0xe03(%rip),%rbx
jmp    1203 <main+0x23>
mov    0x8(%rsi),%rbx
mov    0x2dde(%rip),%r14
mov    (%r14),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0x1c(%rsp)
mov    %rbx,%rsi
call   1050 <strcpy@plt>
call   1040 <unlink@plt>
lea    0x18(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1252 <main+0x72>
lea    0xdc6(%rip),%rdi
jmp    12ae <main+0xce>
mov    %ebp,%edi
mov    $0x20,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0x8c>
lea    0xdb1(%rip),%rdi
jmp    12ae <main+0xce>
lea    0x20(%rsp),%rdi
mov    $0x800,%edx
xor    %esi,%esi
call   1090 <memset@plt>
lea    0xdba(%rip),%rdi
call   1060 <puts@plt>
movl   $0x8,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
jne    12bd <main+0xdd>
lea    0xd74(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    %eax,%r12d
lea    0x20(%rsp),%rbx
lea    0xc(%rsp),%r13
lea    0xd58(%rip),%r14
lea    0xd56(%rip),%r15
jmp    1336 <main+0x156>
lea    0xd58(%rip),%rdi
call   10d0 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
call   10a0 <close@plt>
mov    $0x800,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
lea    0xd30(%rip),%rdi
call   1060 <puts@plt>
movl   $0x8,0xc(%rsp)
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
call   10e0 <accept@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     12a7 <main+0xc7>
lea    0xd1d(%rip),%rdi
call   1060 <puts@plt>
jmp    1378 <main+0x198>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     12da <main+0xfa>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     12f0 <main+0x110>
jns    1350 <main+0x170>
mov    %r14,%rdi
call   10d0 <perror@plt>
jmp    1350 <main+0x170>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [22 x i8] c"/tmp/db_sanitize.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [29 x i8] c"Waiting for a connection...\0A\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [12 x i8] c"Connected.\0A\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [11 x i8] c"got : '%s'\00"
@.str.8 = [5 x i8] c"send\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 %struct.sockaddr_un
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [2048 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %2
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8** %11
br label %23
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %11
br label %23
23: ; preds = %19, %18
%24 = load i32, i32* @AF_UNIX
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %6
%27 = load i32, i32* @AF_UNIX
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = load i8*, i8** %11
%32 = call i32 @strcpy(i32 %30, i8* %31)
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @unlink(i32 %34)
store i32 8, i32* %10
%36 = load i32, i32* %6
%37 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%38 = load i32, i32* %10
%39 = call i32 @bind(i32 %36, %struct.sockaddr* %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %23
%42 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %23
%45 = load i32, i32* %6
%46 = call i32 @listen(i32 %45, i32 32)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %44
br label %52
52: ; preds = %95, %51
%53 = bitcast [2048 x i8]* %15 to i8*
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 8, i32* %14
%55 = load i32, i32* %6
%56 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%57 = call i32 @accept(i32 %55, %struct.sockaddr* %56, i32* %14)
store i32 %57, i32* %7
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %52
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %12
br label %64
64: ; preds = %91, %62
%65 = load i32, i32* %7
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%67 = call i32 @recv(i32 %65, i8* %66, i32 2048, i32 0)
store i32 %67, i32* %13
%68 = load i32, i32* %13
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %64
store i32 1, i32* %12
br label %77
71: ; preds = %64
%72 = load i32, i32* %13
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %71
%75 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %76
76: ; preds = %74, %71
br label %77
77: ; preds = %76, %70
%78 = load i32, i32* %12
%79 = icmp ne i32 %78, 0
br i1 %79, label %90, label %80
80: ; preds = %77
%81 = getelementptr inbounds [2048 x i8], [2048 x i8]* %15, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %81)
%83 = load i32, i32* %7
%84 = bitcast [2048 x i8]* %15 to i8*
%85 = call i64 @send(i32 %83, i8* %84, i32 2048, i32 0)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %80
%88 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %12
br label %89
89: ; preds = %87, %80
br label %90
90: ; preds = %89, %77
br label %91
91: ; preds = %90
%92 = load i32, i32* %12
%93 = icmp ne i32 %92, 0
%94 = xor i1 %93, true
br i1 %94, label %64, label %95
95: ; preds = %91
%96 = load i32, i32* %7
%97 = call i32 @close(i32 %96)
br label %52
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [22 x i8] c"/tmp/db_sanitize.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [11 x i8] c"got : '%s'\00"
@.str.8 = [5 x i8] c"send\00"
@str = [28 x i8] c"Waiting for a connection...\00"
@str.9 = [11 x i8] c"Connected.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca [2048 x i8]
%7 = bitcast %struct.sockaddr_un* %3 to i8*
%8 = bitcast %struct.sockaddr_un* %4 to i8*
%9 = icmp eq i32 %0, 1
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
br label %13
13: ; preds = %2, %10
%14 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %2 ]
%15 = load i32, i32* @AF_UNIX
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = tail call i32 @strcpy(i32 undef, i8* %14)
%21 = tail call i32 @unlink(i32 undef)
%22 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%23 = call i32 @bind(i32 %17, %struct.sockaddr* %22, i32 8)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %13
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %13
%29 = call i32 @listen(i32 %17, i32 32)
%30 = icmp eq i32 %29, -1
br i1 %30, label %38, label %31
31: ; preds = %28
%32 = bitcast i32* %5 to i8*
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
store i32 8, i32* %5
%35 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%36 = call i32 @accept(i32 %17, %struct.sockaddr* %35, i32* %5)
%37 = icmp eq i32 %36, -1
br i1 %37, label %41, label %44
38: ; preds = %28
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %60, %31
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %31, %60
%45 = phi i32 [ %63, %60 ], [ %36, %31 ]
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0))
br label %47
47: ; preds = %54, %44
%48 = call i32 @recv(i32 %45, i8* %33, i32 2048, i32 0)
%49 = icmp eq i32 %48, 0
br i1 %49, label %60, label %50
50: ; preds = %47
%51 = icmp slt i32 %48, 0
br i1 %51, label %52, label %54
52: ; preds = %50
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %33)
%56 = call i64 @send(i32 %45, i8* %33, i32 2048, i32 0)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %47
58: ; preds = %54
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %60
60: ; preds = %47, %58
%61 = call i32 @close(i32 %45)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
store i32 8, i32* %5
%63 = call i32 @accept(i32 %17, %struct.sockaddr* %35, i32* %5)
%64 = icmp eq i32 %63, -1
br i1 %64, label %41, label %44
}