#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*/ buf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ writestr(int, char *);
int main(int argc, char **argv) {
  int fd;
  struct sockaddr_un addr;
  char buf[100];
  int len;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s socket\n", argv[0]);
    return 1;
  }
  fd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (fd < 0) {
    perror("socket");
    return -1;
  }
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, argv[1], sizeof(addr.sun_path) - 1);
  if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    perror("connect");
    return 1;
  }
  writestr(fd, "What is your name?\n");
  len = read(fd, buf, sizeof(buf) - 1);
  assert(len >= 0);
  buf[len] = 0;
  printf("Got name: %s\n", buf);
  writestr(fd, "hello ");
  writestr(fd, buf);
  usleep(20000);
  len = send(fd, "send()", 6, 0);
  assert(len == 6);
  len = recv(fd, buf, sizeof(buf) - 1, 0);
  assert(len > 0);
  buf[len] = 0;
  printf("Got recv: %s\n", buf);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     122b <main+0x4b>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde6(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13e4 <main+0x204>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1269 <main+0x89>
lea    0xdba(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e4 <main+0x204>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12cc <main+0xec>
lea    0xd5e(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13e4 <main+0x204>
mov    -0x14(%rbp),%edi
lea    0xd4b(%rip),%rsi
call   10c0 <writestr@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x63,%edx
call   1090 <read@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
movslq -0x94(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xd0f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xd0e(%rip),%rsi
call   10c0 <writestr@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   10c0 <writestr@plt>
mov    $0x4e20,%edi
call   10f0 <usleep@plt>
mov    -0x14(%rbp),%edi
lea    0xced(%rip),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x6,-0x94(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
movslq -0x94(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xc81(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1335 <main+0x155>
mov    0x2de6(%rip),%r12
mov    (%r12),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1366 <main+0x186>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    (%r12),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
mov    0x8(%rbx),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     137a <main+0x19a>
lea    0xdb1(%rip),%rsi
mov    %ebp,%edi
call   10c0 <writestr@plt>
lea    0x10(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x63,%edx
call   1090 <read@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   10a0 <assert@plt>
movslq %ebx,%rax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xd8d(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
lea    0xd8c(%rip),%rsi
mov    %ebp,%edi
call   10c0 <writestr@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   10c0 <writestr@plt>
mov    $0x4e20,%edi
call   10f0 <usleep@plt>
lea    0xd71(%rip),%rsi
mov    %ebp,%edi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
xor    %edi,%edi
cmp    $0x6,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   10a0 <assert@plt>
movslq %ebx,%rax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xd2d(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    1353 <main+0x173>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcb8(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xca5(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%r15d
jmp    1353 <main+0x173>
lea    0xc98(%rip),%rdi
call   10d0 <perror@plt>
jmp    134d <main+0x16d>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s socket\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [20 x i8] c"What is your name?\0A\00"
@.str.4 = [14 x i8] c"Got name: %s\0A\00"
@.str.5 = [7 x i8] c"hello \00"
@.str.6 = [7 x i8] c"send()\00"
@.str.7 = [14 x i8] c"Got recv: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca [100 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %83
18: ; preds = %2
%19 = load i32, i32* @AF_UNIX
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %83
26: ; preds = %18
%27 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 8)
%28 = load i32, i32* @AF_UNIX
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%31 = load i32, i32* %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @strncpy(i32 %31, i8* %34, i32 3)
%36 = load i32, i32* %6
%37 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%38 = call i32 @connect(i32 %36, %struct.sockaddr* %37, i32 8)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %26
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %83
42: ; preds = %26
%43 = load i32, i32* %6
%44 = call i32 @writestr(i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* %6
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 99)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = icmp sge i32 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %53
store i8 0, i8* %54
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = load i32, i32* %6
%58 = call i32 @writestr(i32 %57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* %6
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%61 = call i32 @writestr(i32 %59, i8* %60)
%62 = call i32 @usleep(i32 20000)
%63 = load i32, i32* %6
%64 = call i32 @send(i32 %63, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6, i32 0)
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp eq i32 %65, 6
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i32, i32* %6
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%71 = call i32 @recv(i32 %69, i8* %70, i32 99, i32 0)
store i32 %71, i32* %9
%72 = load i32, i32* %9
%73 = icmp sgt i32 %72, 0
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i32, i32* %9
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %77
store i8 0, i8* %78
%79 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%80 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %79)
%81 = load i32, i32* %6
%82 = call i32 @close(i32 %81)
store i32 0, i32* %3
br label %83
83: ; preds = %42, %40, %24, %12
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s socket\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [20 x i8] c"What is your name?\0A\00"
@.str.4 = [14 x i8] c"Got name: %s\0A\00"
@.str.5 = [7 x i8] c"hello \00"
@.str.6 = [7 x i8] c"send()\00"
@.str.7 = [14 x i8] c"Got recv: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [100 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %57
12: ; preds = %2
%13 = load i32, i32* @AF_UNIX
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %57
19: ; preds = %12
%20 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%21 = load i32, i32* @AF_UNIX
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strncpy(i32 %24, i8* %26, i32 3)
%28 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%29 = call i32 @connect(i32 %15, %struct.sockaddr* %28, i32 8)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %57
33: ; preds = %19
%34 = call i32 @writestr(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @read(i32 %15, i8* %6, i32 99)
%36 = xor i32 %35, -1
%37 = lshr i32 %36, 31
%38 = call i32 @assert(i32 %37)
%39 = sext i32 %35 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%42 = call i32 @writestr(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @writestr(i32 %15, i8* %6)
%44 = call i32 @usleep(i32 20000)
%45 = call i32 @send(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6, i32 0)
%46 = icmp eq i32 %45, 6
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = call i32 @recv(i32 %15, i8* %6, i32 99, i32 0)
%50 = icmp sgt i32 %49, 0
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = sext i32 %49 to i64
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %53
store i8 0, i8* %54
%55 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%56 = call i32 @close(i32 %15)
br label %57
57: ; preds = %33, %31, %17, %8
%58 = phi i32 [ 1, %8 ], [ -1, %17 ], [ 1, %31 ], [ 0, %33 ]
ret i32 %58
}