#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int send(int, char *, int, int /*<<< orphan*/);
char *sockaddr2str(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int main() {
  int ret;
  int srv_sock;
  struct addrinfo hints, *ai_list;
  char *addrstr;
  char mens[100];
  int sent;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  ret = getaddrinfo("127.0.0.1", "6060", &hints, &ai_list);
  do {
    if (ret != 0) {
      perror("getaddrinfo");
      ret = EXIT_FAILURE;
      goto error;
    }
  } while (0);
  addrstr = sockaddr2str(ai_list->ai_addr);
  srv_sock =
      socket(ai_list->ai_family, ai_list->ai_socktype, ai_list->ai_protocol);
  do {
    if (srv_sock == -1) {
      perror("socket");
      ret = EXIT_FAILURE;
      goto error_free;
    }
  } while (0);
  ret = connect(srv_sock, ai_list->ai_addr, ai_list->ai_addrlen);
  do {
    if (ret == -1) {
      perror("connect");
      ret = EXIT_FAILURE;
      goto close;
    }
  } while (0);
  do {
    fgets(mens, 100, stdin);
    sent = send(srv_sock, mens, 100, 0);
    do {
      if (sent != 100) {
        perror("sent incomplete");
        ret = EXIT_FAILURE;
        goto close;
      }
    } while (0);
  } while (strcmp(mens, "exit\n") != 0);
  ret = EXIT_SUCCESS;
close:
  close(srv_sock);
error_free:
  free(addrstr);
  freeaddrinfo(ai_list);
error:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xdff(%rip),%rdi
lea    0xe02(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     123f <main+0x7f>
lea    0xde6(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1393 <main+0x1d3>
jmp    1244 <main+0x84>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
call   1090 <sockaddr2str@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1298 <main+0xd8>
lea    0xd99(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1381 <main+0x1c1>
jmp    129d <main+0xdd>
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10b0 <connect@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12dc <main+0x11c>
lea    0xd5c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1379 <main+0x1b9>
jmp    12e1 <main+0x121>
jmp    12e6 <main+0x126>
lea    -0xa0(%rbp),%rdi
mov    0x2cec(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fgets@plt>
mov    -0xc(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x64,-0xa4(%rbp)
je     1346 <main+0x186>
lea    0xcfa(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1379 <main+0x1b9>
jmp    134b <main+0x18b>
jmp    1350 <main+0x190>
lea    -0xa0(%rbp),%rdi
lea    0xcdc(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12e6 <main+0x126>
mov    0x2c4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    -0x8(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0xdfa(%rip),%rdi
lea    0xdfd(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
jne    12e6 <main+0x126>
mov    (%rsp),%rax
mov    0x4(%rax),%edi
call   1090 <sockaddr2str@plt>
mov    %rax,%r15
mov    (%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     12fd <main+0x13d>
mov    %eax,%ebp
mov    (%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
je     1314 <main+0x154>
mov    0x2d74(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0xdc2(%rip),%r12
mov    0x2d41(%rip),%r13
nop
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x64,%eax
jne    131d <main+0x15d>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1280 <main+0xc0>
mov    0x0(%r13),%ebx
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    %ebx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd22(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%ebx
jmp    12d2 <main+0x112>
lea    0xd17(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%ebx
jmp    12c1 <main+0x101>
lea    0xd07(%rip),%rdi
jmp    1324 <main+0x164>
lea    0xd06(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c98(%rip),%r13
jmp    12b6 <main+0xf6>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"6060\00"
@.str.2 = [12 x i8] c"getaddrinfo\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [8 x i8] c"connect\00"
@stdin = global i32 0
@.str.5 = [16 x i8] c"sent incomplete\00"
@.str.6 = [6 x i8] c"exit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca i8*
%7 = alloca [100 x i8]
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 20)
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_STREAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 3
store i32 %12, i32* %13
%14 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %5)
store i32 %14, i32* %2
br label %15
15: ; preds = %0
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %2
br label %90
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load %struct.addrinfo*, %struct.addrinfo** %5
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = call i8* @sockaddr2str(i32 %25)
store i8* %26, i8** %6
%27 = load %struct.addrinfo*, %struct.addrinfo** %5
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 4
%29 = load i32, i32* %28
%30 = load %struct.addrinfo*, %struct.addrinfo** %5
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 3
%32 = load i32, i32* %31
%33 = load %struct.addrinfo*, %struct.addrinfo** %5
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 @socket(i32 %29, i32 %32, i32 %35)
store i32 %36, i32* %3
br label %37
37: ; preds = %22
%38 = load i32, i32* %3
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %2
br label %85
43: ; preds = %37
br label %44
44: ; preds = %43
%45 = load i32, i32* %3
%46 = load %struct.addrinfo*, %struct.addrinfo** %5
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = load %struct.addrinfo*, %struct.addrinfo** %5
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @connect(i32 %45, i32 %48, i32 %51)
store i32 %52, i32* %2
br label %53
53: ; preds = %44
%54 = load i32, i32* %2
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %2
br label %82
59: ; preds = %53
br label %60
60: ; preds = %59
br label %61
61: ; preds = %76, %60
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%63 = load i32, i32* @stdin
%64 = call i32 @fgets(i8* %62, i32 100, i32 %63)
%65 = load i32, i32* %3
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%67 = call i32 @send(i32 %65, i8* %66, i32 100, i32 0)
store i32 %67, i32* %8
br label %68
68: ; preds = %61
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 100
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
store i32 %73, i32* %2
br label %82
74: ; preds = %68
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%78 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%79 = icmp ne i64 %78, 0
br i1 %79, label %61, label %80
80: ; preds = %76
%81 = load i32, i32* @EXIT_SUCCESS
store i32 %81, i32* %2
br label %82
82: ; preds = %80, %71, %56
%83 = load i32, i32* %3
%84 = call i32 @close(i32 %83)
br label %85
85: ; preds = %82, %40
%86 = load i8*, i8** %6
%87 = call i32 @free(i8* %86)
%88 = load %struct.addrinfo*, %struct.addrinfo** %5
%89 = call i32 @freeaddrinfo(%struct.addrinfo* %88)
br label %90
90: ; preds = %85, %18
%91 = load i32, i32* %2
ret i32 %91
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"6060\00"
@.str.2 = [12 x i8] c"getaddrinfo\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [8 x i8] c"connect\00"
@stdin = global i32 0
@.str.5 = [16 x i8] c"sent incomplete\00"
@.str.6 = [6 x i8] c"exit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = alloca [100 x i8]
%4 = bitcast %struct.addrinfo* %1 to i8*
%5 = bitcast %struct.addrinfo** %2 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 20)
%8 = load i32, i32* @AF_UNSPEC
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 4
store i32 %8, i32* %9
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 3
store i32 %10, i32* %11
%12 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
br label %62
17: ; preds = %0
%18 = load %struct.addrinfo*, %struct.addrinfo** %2
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %18, i64 0, i32 1
%20 = load i32, i32* %19
%21 = call i8* @sockaddr2str(i32 %20)
%22 = load %struct.addrinfo*, %struct.addrinfo** %2
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 4
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 3
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 2
%28 = load i32, i32* %27
%29 = call i32 @socket(i32 %24, i32 %26, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %17
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
br label %57
34: ; preds = %17
%35 = load %struct.addrinfo*, %struct.addrinfo** %2
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @connect(i32 %29, i32 %37, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %50, label %42
42: ; preds = %34, %47
%43 = load i32, i32* @stdin
%44 = call i32 @fgets(i8* %6, i32 100, i32 %43)
%45 = call i32 @send(i32 %29, i8* %6, i32 100, i32 0)
%46 = icmp eq i32 %45, 100
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %42
50: ; preds = %42, %34
%51 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %34 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), %42 ]
%52 = call i32 @perror(i8* %51)
br label %53
53: ; preds = %47, %50
%54 = phi i32* [ @EXIT_FAILURE, %50 ], [ @EXIT_SUCCESS, %47 ]
%55 = load i32, i32* %54
%56 = call i32 @close(i32 %29)
br label %57
57: ; preds = %53, %31
%58 = phi i32 [ %33, %31 ], [ %55, %53 ]
%59 = call i32 @free(i8* %21)
%60 = load %struct.addrinfo*, %struct.addrinfo** %2
%61 = call i32 @freeaddrinfo(%struct.addrinfo* %60)
br label %62
62: ; preds = %57, %14
%63 = phi i32 [ %16, %14 ], [ %58, %57 ]
ret i32 %63
}