#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*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  struct sockaddr_un address;
  int sockfd;
  int len;
  int i, bytes;
  int result;
  char ch_recv, ch_send;
  if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  address.sun_family = AF_UNIX;
  strcpy(address.sun_path, "server_socket");
  len = sizeof(address);
  result = connect(sockfd, (struct sockaddr *)&address, len);
  if (result == -1) {
    printf("ensure the server is up\n");
    perror("connect");
    exit(EXIT_FAILURE);
  }
  for (i = 0, ch_send = 'A'; i < 0xfffffffffffffff5; i++, ch_send++) {
    if ((bytes = write(sockfd, &ch_send, 1)) == -1) {
      perror("write");
      exit(EXIT_FAILURE);
    }
    sleep(2);
    if ((bytes = read(sockfd, &ch_recv, 1)) == -1) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    printf("receive from server data is %c\n", ch_recv);
  }
  close(sockfd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11f5 <main+0x55>
lea    0xe25(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    0xdf5(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x8,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   10a0 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    125b <main+0xbb>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xddf(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,-0x24(%rbp)
movb   $0x41,-0x2e(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0xfffffffffffffff5,%rax
jae    1314 <main+0x174>
mov    -0x1c(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    12ab <main+0x10b>
lea    0xd97(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
mov    -0x1c(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    12ec <main+0x14c>
lea    0xd5c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movsbl -0x2d(%rbp),%esi
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x2e(%rbp),%al
add    $0x1,%al
mov    %al,-0x2e(%rbp)
jmp    1266 <main+0xc6>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e35(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
jne    11d6 <main+0x36>
lea    0xe36(%rip),%rdi
jmp    12a8 <main+0x108>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
lea    0xe1b(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1218 <main+0x78>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
lea    0xdfb(%rip),%rdi
jmp    12a8 <main+0x108>
movb   $0x41,0x6(%rsp)
lea    0x6(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
je     1298 <main+0xf8>
mov    $0x42,%bl
lea    0x7(%rsp),%r14
lea    0xde0(%rip),%r15
lea    0x6(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    $0x2,%edi
call   10b0 <sleep@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     12a1 <main+0x101>
movsbl 0x7(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %bl,0x6(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
add    $0x1,%bl
cmp    $0xffffffff,%eax
jne    1250 <main+0xb0>
lea    0xd77(%rip),%rdi
jmp    12a8 <main+0x108>
lea    0xd74(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"server_socket\00"
@.str.2 = [25 x i8] c"ensure the server is up\0A\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [32 x i8] c"receive from server data is %c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* @AF_UNIX
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @strcpy(i32 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 8, i32* %8
%28 = load i32, i32* %7
%29 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%30 = load i32, i32* %8
%31 = call i32 @connect(i32 %28, %struct.sockaddr* %29, i32 %30)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %22
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %22
store i32 0, i32* %9
store i8 65, i8* %13
br label %40
40: ; preds = %65, %39
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = icmp ult i64 %42, -11
br i1 %43, label %44, label %70
44: ; preds = %40
%45 = load i32, i32* %7
%46 = call i32 @write(i32 %45, i8* %13, i32 1)
store i32 %46, i32* %10
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %44
%53 = call i32 @sleep(i32 2)
%54 = load i32, i32* %7
%55 = call i32 @read(i32 %54, i8* %12, i32 1)
store i32 %55, i32* %10
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %61
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %52
%62 = load i8, i8* %12
%63 = sext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %61
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
%68 = load i8, i8* %13
%69 = add i8 %68, 1
store i8 %69, i8* %13
br label %40
70: ; preds = %40
%71 = load i32, i32* %7
%72 = call i32 @close(i32 %71)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"server_socket\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [32 x i8] c"receive from server data is %c\0A\00"
@str = [24 x i8] c"ensure the server is up\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca i8
%5 = alloca i8
%6 = bitcast %struct.sockaddr_un* %3 to i8*
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%20 = call i32 @connect(i32 %9, %struct.sockaddr* %19, i32 8)
%21 = icmp eq i32 %20, -1
br i1 %21, label %25, label %22
22: ; preds = %15
store i8 65, i8* %5
%23 = call i32 @write(i32 %9, i8* %5, i32 1)
%24 = icmp eq i32 %23, -1
br i1 %24, label %30, label %34
25: ; preds = %15
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %43, %22
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %22, %43
%35 = phi i8 [ %47, %43 ], [ 65, %22 ]
%36 = call i32 @sleep(i32 2)
%37 = call i32 @read(i32 %9, i8* %4, i32 1)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
%44 = load i8, i8* %4
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = add i8 %35, 1
store i8 %47, i8* %5
%48 = call i32 @write(i32 %9, i8* %5, i32 1)
%49 = icmp eq i32 %48, -1
br i1 %49, label %30, label %34
}