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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
scalar_t__ getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int opt;
  char *server_port = "5555";
  char *server_ip;
  char *name;
  char *msg;
  char buf[128];
  struct addrinfo hints, *server;
  int sockfd;
  int ret;
  if (argc < 4) {
    fprintf(stderr, "Usage: %s hostname name msg\n", argv[0]);
    exit(1);
  }
  server_ip = argv[1];
  name = argv[2];
  msg = argv[3];
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  if (ret = getaddrinfo(server_ip, server_port, &hints, &server) != 0) {
    perror(gai_strerror(ret));
    exit(-1);
  }
  sockfd = socket(server->ai_family, server->ai_socktype, server->ai_protocol);
  if (sockfd == -1) {
    perror("ERROR open socket");
    exit(-1);
  }
  ret = connect(sockfd, server->ai_addr, server->ai_addrlen);
  if (ret == -1) {
    perror("ERROR on connect");
    close(sockfd);
    exit(-1);
  }
  printf("name:%s\n", name);
  printf("msg:%s\n", msg);
  snprintf(buf, sizeof(buf) - 1, "%s\n%s\n", name, msg);
  send(sockfd, buf, strlen(buf), 0);
  close(sockfd);
  printf("Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1224 <main+0x54>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf0(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0xd8(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1080 <memset@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc8(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xcc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0xd8(%rbp),%rdx
lea    -0xe0(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0xe8(%rbp)
test   $0x1,%al
jne    12b6 <main+0xe6>
jmp    12d3 <main+0x103>
mov    -0xe8(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0xe0(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0xe0(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0xe0(%rbp),%rax
mov    0x8(%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0xe4(%rbp)
cmpl   $0xffffffff,-0xe4(%rbp)
jne    131f <main+0x14f>
lea    0xd12(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0xe4(%rbp),%edi
mov    -0xe0(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0xe0(%rbp),%rax
mov    (%rax),%edx
call   10d0 <connect@plt>
mov    %eax,-0xe8(%rbp)
cmpl   $0xffffffff,-0xe8(%rbp)
jne    1371 <main+0x1a1>
lea    0xcdd(%rip),%rdi
call   10b0 <perror@plt>
mov    -0xe4(%rbp),%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rsi
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    $0x7f,%esi
lea    0xca6(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0xe4(%rbp),%eax
mov    %eax,-0xf4(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xc0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xf4(%rbp),%edi
mov    -0xf0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0xe4(%rbp),%edi
call   1090 <close@plt>
lea    0xc5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
cmp    $0x3,%edi
jle    12fe <main+0x11e>
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%r15
mov    0x18(%rsi),%r14
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1090 <memset@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0xdc9(%rip),%rsi
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10f0 <getaddrinfo@plt>
test   %rax,%rax
jne    1320 <main+0x140>
mov    (%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     132f <main+0x14f>
mov    %eax,%ebp
mov    (%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     1345 <main+0x165>
lea    0xdba(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdb2(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xda9(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7f,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
lea    0xd74(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xcf4(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x1,%edi
call   1080 <gai_strerror@plt>
mov    %rax,%rdi
jmp    1336 <main+0x156>
lea    0xcec(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xce8(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [5 x i8] c"5555\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s hostname name msg\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"ERROR open socket\00"
@.str.3 = [17 x i8] c"ERROR on connect\00"
@.str.4 = [9 x i8] c"name:%s\0A\00"
@.str.5 = [8 x i8] c"msg:%s\0A\00"
@.str.6 = [7 x i8] c"%s\0A%s\0A\00"
@.str.7 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [128 x i8]
%12 = alloca %struct.addrinfo
%13 = alloca %struct.addrinfo*
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %8
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %9
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
store i8* %34, i8** %10
%35 = call i32 @memset(%struct.addrinfo* %12, i32 0, i32 20)
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 4
store i32 %36, i32* %37
%38 = load i32, i32* @SOCK_STREAM
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 3
store i32 %38, i32* %39
%40 = load i8*, i8** %8
%41 = load i8*, i8** %7
%42 = call i64 @getaddrinfo(i8* %40, i8* %41, %struct.addrinfo* %12, %struct.addrinfo** %13)
%43 = icmp ne i64 %42, 0
%44 = zext i1 %43 to i32
store i32 %44, i32* %15
br i1 %43, label %45, label %50
45: ; preds = %25
%46 = load i32, i32* %15
%47 = call i8* @gai_strerror(i32 %46)
%48 = call i32 @perror(i8* %47)
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %25
%51 = load %struct.addrinfo*, %struct.addrinfo** %13
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %51, i32 0, i32 4
%53 = load i32, i32* %52
%54 = load %struct.addrinfo*, %struct.addrinfo** %13
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 3
%56 = load i32, i32* %55
%57 = load %struct.addrinfo*, %struct.addrinfo** %13
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 2
%59 = load i32, i32* %58
%60 = call i32 @socket(i32 %53, i32 %56, i32 %59)
store i32 %60, i32* %14
%61 = load i32, i32* %14
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %50
%64 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %50
%67 = load i32, i32* %14
%68 = load %struct.addrinfo*, %struct.addrinfo** %13
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 1
%70 = load i32, i32* %69
%71 = load %struct.addrinfo*, %struct.addrinfo** %13
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @connect(i32 %67, i32 %70, i32 %73)
store i32 %74, i32* %15
%75 = load i32, i32* %15
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %82
77: ; preds = %66
%78 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%79 = load i32, i32* %14
%80 = call i32 @close(i32 %79)
%81 = call i32 @exit(i32 -1)
unreachable
82: ; preds = %66
%83 = load i8*, i8** %9
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %83)
%85 = load i8*, i8** %10
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %85)
%87 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%88 = load i8*, i8** %9
%89 = load i8*, i8** %10
%90 = call i32 @snprintf(i8* %87, i32 127, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %88, i8* %89)
%91 = load i32, i32* %14
%92 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%93 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%94 = call i32 @strlen(i8* %93)
%95 = call i32 @send(i32 %91, i8* %92, i32 %94, i32 0)
%96 = load i32, i32* %14
%97 = call i32 @close(i32 %96)
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [5 x i8] c"5555\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s hostname name msg\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"ERROR open socket\00"
@.str.3 = [17 x i8] c"ERROR on connect\00"
@.str.4 = [9 x i8] c"name:%s\0A\00"
@.str.5 = [8 x i8] c"msg:%s\0A\00"
@.str.6 = [7 x i8] c"%s\0A%s\0A\00"
@str = [6 x i8] c"Done.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.addrinfo* %4 to i8*
%8 = bitcast %struct.addrinfo** %5 to i8*
%9 = icmp slt i32 %0, 4
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 20)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @SOCK_STREAM
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %25, i32* %26
%27 = call i64 @getaddrinfo(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %15
%30 = call i8* @gai_strerror(i32 1)
%31 = call i32 @perror(i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %15
%34 = load %struct.addrinfo*, %struct.addrinfo** %5
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 4
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 3
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 2
%40 = load i32, i32* %39
%41 = call i32 @socket(i32 %36, i32 %38, i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %33
%44 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %33
%47 = load %struct.addrinfo*, %struct.addrinfo** %5
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 1
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @connect(i32 %41, i32 %49, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %46
%55 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @close(i32 %41)
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %46
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %21)
%61 = call i32 @snprintf(i8* %6, i32 127, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %19, i8* %21)
%62 = call i32 @strlen(i8* %6)
%63 = call i32 @send(i32 %41, i8* %6, i32 %62, i32 0)
%64 = call i32 @close(i32 %41)
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}