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

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int gethostname(char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int sock_connect(char *, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int skfd, slen, rlen;
  char buf[128] = {0};
  char hostnm[64] = {0};
  time_t tm;
  if (argc != 3) {
    printf("Usage: ./epoll_clt [IP address] [Port number]\n");
    exit(EXIT_FAILURE);
  }
  skfd = sock_connect(argv[1], argv[2]);
  if (skfd == -1) {
    exit(EXIT_FAILURE);
  }
  if (gethostname(hostnm, sizeof(hostnm) - 1) == -1) {
    perror("get_host_name");
    exit(-1);
  }
  do {
    sleep(1);
    time(&tm);
    snprintf(buf, sizeof(buf), "From client %s %s", hostnm, ctime(&tm));
    slen = send(skfd, buf, strlen(buf), 0);
    if (slen != strlen(buf)) {
      printf("Send msg failed! slen (%d)\n", slen);
      break;
    }
    memset(buf, 0, sizeof(buf));
    rlen = recv(skfd, buf, sizeof(buf), 0);
    if (rlen == -1) {
      printf("Recv message failed !\n");
      break;
    } else if (rlen == 0) {
      printf("Recv nothing!\n");
      break;
    } else {
      printf("Recv : %s\n", buf);
    }
  } while (1);
  close(skfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1090 <memset@plt>
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1090 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
je     1245 <main+0x65>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1100 <sock_connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1275 <main+0x95>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0xe0(%rbp),%rdi
mov    $0x3f,%esi
call   10d0 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    12a5 <main+0xc5>
lea    0xd99(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
jmp    12aa <main+0xca>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    -0xe4(%rbp),%rdi
call   10b0 <time@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0x108(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    -0xe4(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x108(%rbp),%rdi
mov    -0x100(%rbp),%rcx
mov    %rax,%r8
mov    $0x80,%esi
lea    0xd38(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xf4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xf4(%rbp),%edi
mov    -0xf0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xe8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0xe8(%rbp),%eax
cmp    %ecx,%eax
je     1381 <main+0x1a1>
mov    -0x18(%rbp),%esi
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1415 <main+0x235>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1090 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    13ca <main+0x1ea>
lea    0xcad(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1415 <main+0x235>
cmpl   $0x0,-0x1c(%rbp)
jne    13e7 <main+0x207>
lea    0xca7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1415 <main+0x235>
lea    -0xa0(%rbp),%rsi
lea    0xc9c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1401 <main+0x221>
jmp    1406 <main+0x226>
mov    $0x1,%al
test   $0x1,%al
jne    12aa <main+0xca>
jmp    1415 <main+0x235>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0x3,%edi
jne    1378 <main+0x188>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1110 <sock_connect@plt>
cmp    $0xffffffff,%eax
je     1384 <main+0x194>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
mov    $0x3f,%esi
call   10e0 <gethostname@plt>
cmp    $0xffffffff,%eax
je     1392 <main+0x1a2>
lea    0xc(%rsp),%r14
lea    0xd7a(%rip),%r15
lea    0x50(%rsp),%rbx
lea    0x10(%rsp),%r12
xchg   %ax,%ax
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    %r14,%rdi
call   10c0 <time@plt>
mov    %r14,%rdi
call   1050 <ctime@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %rax,%r8
call   1090 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    %eax,%r13d
jne    1335 <main+0x145>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10a0 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1348 <main+0x158>
cmp    $0xffffffff,%eax
je     1351 <main+0x161>
lea    0xd16(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12a0 <main+0xb0>
lea    0xce4(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    135d <main+0x16d>
lea    0xcf8(%rip),%rdi
jmp    1358 <main+0x168>
lea    0xcfd(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcec(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xc67(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Usage: ./epoll_clt [IP address] [Port number]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"get_host_name\00"
@.str.2 = [18 x i8] c"From client %s %s\00"
@.str.3 = [28 x i8] c"Send msg failed! slen (%d)\0A\00"
@.str.4 = [23 x i8] c"Recv message failed !\0A\00"
@.str.5 = [15 x i8] c"Recv nothing!\0A\00"
@.str.6 = [11 x i8] c"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 i32
%8 = alloca i32
%9 = alloca [128 x i8]
%10 = alloca [64 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [128 x i8]* %9 to i8*
%13 = bitcast [64 x i8]* %10 to i8*
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @sock_connect(i8* %23, i8* %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %20
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %20
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%35 = call i32 @gethostname(i8* %34, i32 63)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %33
br label %41
41: ; preds = %80, %40
%42 = call i32 @sleep(i32 1)
%43 = call i32 @time(i32* %11)
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%46 = call i8* @ctime(i32* %11)
%47 = call i32 @snprintf(i8* %44, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %46)
%48 = load i32, i32* %6
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
%52 = call i32 @send(i32 %48, i8* %49, i32 %51, i32 0)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = icmp ne i32 %53, %55
br i1 %56, label %57, label %60
57: ; preds = %41
%58 = load i32, i32* %7
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %81
60: ; preds = %41
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%62 = call i32 @memset(i8* %61, i32 0, i32 128)
%63 = load i32, i32* %6
%64 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%65 = call i32 @recv(i32 %63, i8* %64, i32 128, i32 0)
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %60
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %81
70: ; preds = %60
%71 = load i32, i32* %8
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %81
75: ; preds = %70
%76 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %75
br label %79
79: ; preds = %78
br label %80
80: ; preds = %79
br i1 true, label %41, label %81
81: ; preds = %80, %73, %68, %57
%82 = load i32, i32* %6
%83 = call i32 @close(i32 %82)
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"get_host_name\00"
@.str.2 = [18 x i8] c"From client %s %s\00"
@.str.3 = [28 x i8] c"Send msg failed! slen (%d)\0A\00"
@.str.6 = [11 x i8] c"Recv : %s\0A\00"
@str = [14 x i8] c"Recv nothing!\00"
@str.7 = [22 x i8] c"Recv message failed !\00"
@str.8 = [46 x i8] c"Usage: ./epoll_clt [IP address] [Port number]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.8, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @sock_connect(i8* %16, i8* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = call i32 @gethostname(i8* %7, i32 63)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %24, %48
%31 = call i32 @sleep(i32 1)
%32 = call i32 @time(i32* %5)
%33 = call i8* @ctime(i32* %5)
%34 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %33)
%35 = call i32 @strlen(i8* %6)
%36 = call i32 @send(i32 %19, i8* %6, i32 %35, i32 0)
%37 = call i32 @strlen(i8* %6)
%38 = icmp eq i32 %36, %37
br i1 %38, label %41, label %39
39: ; preds = %30
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %36)
br label %50
41: ; preds = %30
%42 = call i32 @memset(i8* %6, i32 0, i32 128)
%43 = call i32 @recv(i32 %19, i8* %6, i32 128, i32 0)
switch i32 %43, label %48 [
i32 -1, label %44
i32 0, label %46
]
44: ; preds = %41
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
br label %50
46: ; preds = %41
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %50
48: ; preds = %41
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %6)
br label %30
50: ; preds = %46, %44, %39
%51 = call i32 @close(i32 %19)
ret i32 0
}