#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;
};

/* Variables and functions */
void *AF_UNIX;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  struct sockaddr_un svaddr, claddr;
  int sfd;
  char buf[512] = {'\0'};
  char read_buf[512] = {'\0'};
  char got_buf[512] = {'\0'};
  sfd = socket(AF_UNIX, SOCK_DGRAM, 0);
  if (sfd == -1)
    perror("socket");
  remove("/tmp/newclientsocket");
  memset(&claddr, 0, sizeof(struct sockaddr_un));
  claddr.sun_family = AF_UNIX;
  strcpy(claddr.sun_path, "/tmp/newclientsocket");
  if (bind(sfd, (struct sockaddr *)&claddr, sizeof(struct sockaddr_un)) == -1)
    perror("bind");
  memset(&svaddr, 0, sizeof(struct sockaddr_un));
  svaddr.sun_family = AF_UNIX;
  strcpy(svaddr.sun_path, "/tmp/serversocket");
  for (;;) {
    printf("Search : ");
    scanf("%s", read_buf);
    sendto(sfd, read_buf, 512, 0, (struct sockaddr *)&svaddr,
           sizeof(struct sockaddr_un));
    recvfrom(sfd, buf, 512, 0, NULL, NULL);
    printf("Infinfty Server Response: \n%s \n\n", buf);
    fflush(stdin);
    fflush(stdout);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    -0x640(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1235 <main+0x85>
lea    0xdf5(%rip),%rdi
call   10c0 <perror@plt>
lea    0xdc4(%rip),%rdi
call   1030 <remove@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%edi
lea    0xd97(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1294 <main+0xe4>
lea    0xd86(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%edi
lea    0xd5e(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x440(%rbp),%rsi
lea    0xd59(%rip),%rdi
call   10a0 <scanf@plt>
mov    -0x34(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    -0x34(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
lea    -0x240(%rbp),%rsi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    12c1 <main+0x111>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
lea    0x220(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x20(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2dfb(%rip),%r15
mov    (%r15),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     131e <main+0x16e>
lea    0xdee(%rip),%rbp
mov    %rbp,%rdi
call   1030 <remove@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%edi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     132f <main+0x17f>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
mov    (%rsp),%edi
lea    0xd9f(%rip),%rsi
call   1040 <strcpy@plt>
lea    0x20(%rsp),%r13
lea    0x220(%rsp),%rbp
lea    0xda5(%rip),%r14
mov    0x2d45(%rip),%r15
mov    0x2d26(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd75(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd71(%rip),%rdi
mov    %r13,%rsi
call   10a0 <scanf@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %rsp,%r8
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%edi
call   1080 <fflush@plt>
mov    (%r12),%edi
call   1080 <fflush@plt>
jmp    12b0 <main+0x100>
lea    0xd00(%rip),%rdi
call   10c0 <perror@plt>
jmp    120b <main+0x5b>
lea    0xcdf(%rip),%rdi
call   10c0 <perror@plt>
jmp    125a <main+0xaa>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [21 x i8] c"/tmp/newclientsocket\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [18 x i8] c"/tmp/serversocket\00"
@.str.4 = [10 x i8] c"Search : \00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [33 x i8] c"Infinfty Server Response: \0A%s \0A\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca [512 x i8]
%11 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [512 x i8]* %9 to i8*
%13 = bitcast [512 x i8]* %10 to i8*
%14 = bitcast [512 x i8]* %11 to i8*
%15 = load i8*, i8** @AF_UNIX
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i8* %15, i32 %16, i32 0)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = call i32 @remove(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 16)
%25 = load i8*, i8** @AF_UNIX
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i8* %25, i8** %26
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @strcpy(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* %8
%31 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%32 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 16)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %22
%37 = call i32 @memset(%struct.sockaddr_un* %6, i32 0, i32 16)
%38 = load i8*, i8** @AF_UNIX
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i8* %38, i8** %39
%40 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @strcpy(i32 %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %43, %36
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = load i32, i32* %8
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%49 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%50 = call i32 @sendto(i32 %47, i8* %48, i32 512, i32 0, %struct.sockaddr* %49, i32 16)
%51 = load i32, i32* %8
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%53 = call i32 @recvfrom(i32 %51, i8* %52, i32 512, i32 0, i32* null, i32* null)
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @stdin
%57 = call i32 @fflush(i32 %56)
%58 = load i32, i32* @stdout
%59 = call i32 @fflush(i32 %58)
br label %43
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [21 x i8] c"/tmp/newclientsocket\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [18 x i8] c"/tmp/serversocket\00"
@.str.4 = [10 x i8] c"Search : \00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [33 x i8] c"Infinfty Server Response: \0A%s \0A\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = bitcast %struct.sockaddr_un* %3 to i8*
%8 = bitcast %struct.sockaddr_un* %4 to i8*
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** @AF_UNIX
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i8* %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = tail call i32 @remove(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @memset(%struct.sockaddr_un* %4, i32 0, i32 16)
%20 = load i8*, i8** @AF_UNIX
%21 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i8* %20, i8** %21
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strcpy(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%25 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%26 = call i32 @bind(i32 %13, %struct.sockaddr* %25, i32 16)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %17
%31 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 16)
%32 = load i8*, i8** @AF_UNIX
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i8* %32, i8** %33
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @strcpy(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%37 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
br label %38
38: ; preds = %38, %30
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%41 = call i32 @sendto(i32 %13, i8* %10, i32 512, i32 0, %struct.sockaddr* %37, i32 16)
%42 = call i32 @recvfrom(i32 %13, i8* %9, i32 512, i32 0, i32* null, i32* null)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %9)
%44 = load i32, i32* @stdin
%45 = call i32 @fflush(i32 %44)
%46 = load i32, i32* @stdout
%47 = call i32 @fflush(i32 %46)
br label %38
}