#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ saddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ INADDR_NONE;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, size_t);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, size_t, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
main(int argc, char *argv[]) {
  int tcpfd;
  size_t size;
  int ret;
  int k, n;
  int port;
  struct sockaddr_in saddr;
  struct hostent *server;
  char buf[512] = "Hello";
  char server_name[64];
  tcpfd = socket(AF_INET, SOCK_STREAM, 0);
  if (tcpfd < 0) {
    perror("socket: fails");
    exit(EXIT_FAILURE);
  } else
    printf("socket: ok\n");
  size = sizeof(saddr);
  bzero((char *)&saddr, size);
  saddr.sin_family = AF_INET;
  if (argc > 1)
    strcpy(server_name, argv[1]);
  server = gethostbyname(server_name);
  if (server == NULL) {
    saddr.sin_addr.s_addr = inet_addr(server_name);
    if (saddr.sin_addr.s_addr == INADDR_NONE) {
      fprintf(stderr, "Bad name/address: %s\n", server_name);
      exit(EXIT_FAILURE);
    }
  } else
    bcopy((char *)server->h_addr, (char *)&saddr.sin_addr.s_addr,
          server->h_length);
  if (argc > 2)
    port = atoi(argv[2]);
  else {
    port = 1100;
    printf("Set port# to default: %d\n", port);
  }
  saddr.sin_port = htons(port);
  ret = connect(tcpfd, (struct sockaddr *)&saddr, size);
  if (ret < 0) {
    fprintf(stderr, "connect to %s:%d: fail\n", server_name, port);
    exit(EXIT_FAILURE);
  } else
    printf("connect to %s: ok\n", server_name);
  for (k = 0; k < 3; k++) {
    printf("TX: ");
    bzero(buf, 512);
    fgets(buf, 512 - 1, stdin);
    size = strlen(buf);
    n = send(tcpfd, buf, size, 0);
    printf("Request to  send %d bytes; Sent %d bytes\n", size, n);
    bzero(buf, 512);
    size = recv(tcpfd, buf, 512, 0);
    printf("RX: %s\n", buf);
  }
  close(tcpfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x250(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1090 <memset@plt>
movb   $0x48,-0x250(%rbp)
movb   $0x65,-0x24f(%rbp)
movb   $0x6c,-0x24e(%rbp)
movb   $0x6c,-0x24d(%rbp)
movb   $0x6f,-0x24c(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12bf <main+0x8f>
lea    0xd54(%rip),%rdi
call   1100 <perror@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movq   $0x18,-0x20(%rbp)
lea    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
call   1110 <bzero@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    130e <main+0xde>
lea    -0x290(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0x290(%rbp),%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    137e <main+0x14e>
lea    -0x290(%rbp),%rdi
call   10c0 <inet_addr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2c9c(%rip),%rcx
cmp    (%rcx),%rax
jne    1379 <main+0x149>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    -0x290(%rbp),%rdx
lea    0xcb6(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
jmp    1399 <main+0x169>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x48(%rbp),%rsi
add    $0x8,%rsi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   10f0 <bcopy@plt>
cmpl   $0x2,-0x8(%rbp)
jle    13b8 <main+0x188>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    13d0 <main+0x1a0>
movl   $0x44c,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x30(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1140 <connect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1427 <main+0x1f7>
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
lea    -0x290(%rbp),%rdx
mov    -0x30(%rbp),%ecx
lea    0xc38(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
lea    -0x290(%rbp),%rsi
lea    0xc2d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    1511 <main+0x2e1>
lea    0xc21(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x250(%rbp),%rdi
mov    $0x200,%esi
call   1110 <bzero@plt>
lea    -0x250(%rbp),%rdi
mov    0x2b5e(%rip),%rax
mov    (%rax),%edx
mov    $0x1ff,%esi
call   10b0 <fgets@plt>
lea    -0x250(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xbbe(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x250(%rbp),%rdi
mov    $0x200,%esi
call   1110 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x20(%rbp)
lea    -0x250(%rbp),%rsi
lea    0xba8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1443 <main+0x213>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x268,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x60(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   10a0 <memset@plt>
movl   $0x6c6c6548,0x60(%rsp)
6c
movb   $0x6f,0x64(%rsp)
mov    0x2d6d(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
test   %eax,%eax
js     1529 <main+0x2e9>
mov    %eax,%r13d
lea    0xe00(%rip),%rdi
call   1050 <puts@plt>
lea    0x8(%rsp),%rdi
mov    $0x18,%esi
call   1120 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
cmp    $0x2,%ebx
jl     12ce <main+0x8e>
mov    0x8(%r14),%rsi
lea    0x20(%rsp),%rdi
call   1040 <strcpy@plt>
lea    0x20(%rsp),%rdi
call   10e0 <gethostbyname@plt>
test   %rax,%rax
je     12ef <main+0xaf>
mov    0x8(%rax),%rsi
lea    0x10(%rsp),%rdi
mov    (%rax),%edx
call   1100 <memmove@plt>
jmp    130e <main+0xce>
lea    0x20(%rsp),%rdi
call   10d0 <inet_addr@plt>
mov    %rax,0x10(%rsp)
mov    0x2cdb(%rip),%rcx
cmp    (%rcx),%rax
je     1557 <main+0x317>
cmp    $0x3,%ebx
jl     1320 <main+0xe0>
mov    0x10(%r14),%rdi
call   1130 <atoi@plt>
mov    %eax,%ebx
jmp    1338 <main+0xf8>
lea    0xcfd(%rip),%rdi
mov    $0x44c,%ebx
mov    $0x44c,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %ebx,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x18,%edx
mov    %r13d,%edi
call   1150 <connect@plt>
test   %eax,%eax
js     1537 <main+0x2f7>
lea    0xcf2(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xcf2(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1120 <bzero@plt>
mov    0x2c41(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1080 <send@plt>
lea    0xca5(%rip),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1120 <bzero@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xc9a(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xc57(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1120 <bzero@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1120 <bzero@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xbd6(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1120 <bzero@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1120 <bzero@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xad0(%rip),%rdi
call   1110 <perror@plt>
jmp    1573 <main+0x333>
mov    0x2a8a(%rip),%rax
mov    (%rax),%edi
lea    0xaf7(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   10f0 <fprintf@plt>
jmp    1573 <main+0x333>
mov    0x2a6a(%rip),%rax
mov    (%rax),%edi
lea    0xaa7(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10f0 <fprintf@plt>
mov    0x2a3e(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"socket: fails\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"socket: ok\0A\00"
@INADDR_NONE = global i64 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Bad name/address: %s\0A\00"
@.str.3 = [26 x i8] c"Set port# to default: %d\0A\00"
@.str.4 = [24 x i8] c"connect to %s:%d: fail\0A\00"
@.str.5 = [19 x i8] c"connect to %s: ok\0A\00"
@.str.6 = [5 x i8] c"TX: \00"
@stdin = global i32 0
@.str.7 = [42 x i8] c"Request to send %d bytes; Sent %d bytes\0A\00"
@.str.8 = [8 x i8] c"RX: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.hostent*
%14 = alloca [512 x i8]
%15 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [512 x i8]* %14 to i8*
%17 = bitcast i8* %16 to [512 x i8]*
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i32 0, i32 0
store i8 72, i8* %18
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i32 0, i32 1
store i8 101, i8* %19
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i32 0, i32 2
store i8 108, i8* %20
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i32 0, i32 3
store i8 108, i8* %21
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i32 0, i32 4
store i8 111, i8* %22
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %2
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32
store i64 24, i64* %7
%35 = bitcast %struct.sockaddr_in* %12 to i8*
%36 = load i64, i64* %7
%37 = trunc i64 %36 to i32
%38 = call i32 @bzero(i8* %35, i32 %37)
%39 = load i32, i32* @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %39, i32* %40
%41 = load i32, i32* %4
%42 = icmp sgt i32 %41, 1
br i1 %42, label %43, label %49
43: ; preds = %34
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @strcpy(i8* %44, i8* %47)
br label %49
49: ; preds = %43, %34
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%51 = call %struct.hostent* @gethostbyname(i8* %50)
store %struct.hostent* %51, %struct.hostent** %13
%52 = load %struct.hostent*, %struct.hostent** %13
%53 = icmp eq %struct.hostent* %52, null
br i1 %53, label %54, label %71
54: ; preds = %49
%55 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%56 = call i64 @inet_addr(i8* %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
store i64 %56, i64* %58
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%60 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %59, i32 0, i32 0
%61 = load i64, i64* %60
%62 = load i64, i64* @INADDR_NONE
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %70
64: ; preds = %54
%65 = load i32, i32* @stderr
%66 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%67 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %66)
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %54
br label %83
71: ; preds = %49
%72 = load %struct.hostent*, %struct.hostent** %13
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %72, i32 0, i32 1
%74 = load i64, i64* %73
%75 = inttoptr i64 %74 to i8*
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%77 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %76, i32 0, i32 0
%78 = bitcast i64* %77 to i8*
%79 = load %struct.hostent*, %struct.hostent** %13
%80 = getelementptr inbounds %struct.hostent, %struct.hostent* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i32 @bcopy(i8* %75, i8* %78, i32 %81)
br label %83
83: ; preds = %71, %70
%84 = load i32, i32* %4
%85 = icmp sgt i32 %84, 2
br i1 %85, label %86, label %91
86: ; preds = %83
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 2
%89 = load i8*, i8** %88
%90 = call i32 @atoi(i8* %89)
store i32 %90, i32* %11
br label %94
91: ; preds = %83
store i32 1100, i32* %11
%92 = load i32, i32* %11
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %91, %86
%95 = load i32, i32* %11
%96 = call i32 @htons(i32 %95)
%97 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %96, i32* %97
%98 = load i32, i32* %6
%99 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%100 = load i64, i64* %7
%101 = call i32 @connect(i32 %98, %struct.sockaddr* %99, i64 %100)
store i32 %101, i32* %8
%102 = load i32, i32* %8
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %111
104: ; preds = %94
%105 = load i32, i32* @stderr
%106 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%107 = load i32, i32* %11
%108 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %106, i32 %107)
%109 = load i32, i32* @EXIT_FAILURE
%110 = call i32 @exit(i32 %109)
unreachable
111: ; preds = %94
%112 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %112)
br label %114
114: ; preds = %111
store i32 0, i32* %9
br label %115
115: ; preds = %141, %114
%116 = load i32, i32* %9
%117 = icmp slt i32 %116, 3
br i1 %117, label %118, label %144
118: ; preds = %115
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%120 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%121 = call i32 @bzero(i8* %120, i32 512)
%122 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%123 = load i32, i32* @stdin
%124 = call i32 @fgets(i8* %122, i32 511, i32 %123)
%125 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%126 = call i64 @strlen(i8* %125)
store i64 %126, i64* %7
%127 = load i32, i32* %6
%128 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%129 = load i64, i64* %7
%130 = call i32 @send(i32 %127, i8* %128, i64 %129, i32 0)
store i32 %130, i32* %10
%131 = load i64, i64* %7
%132 = load i32, i32* %10
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i64 %131, i32 %132)
%134 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%135 = call i32 @bzero(i8* %134, i32 512)
%136 = load i32, i32* %6
%137 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%138 = call i64 @recv(i32 %136, i8* %137, i32 512, i32 0)
store i64 %138, i64* %7
%139 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %139)
br label %141
141: ; preds = %118
%142 = load i32, i32* %9
%143 = add nsw i32 %142, 1
store i32 %143, i32* %9
br label %115
144: ; preds = %115
%145 = load i32, i32* %6
%146 = call i32 @close(i32 %145)
%147 = load i32, i32* %3
ret i32 %147
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"socket: fails\00"
@EXIT_FAILURE = global i32 0
@INADDR_NONE = global i64 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Bad name/address: %s\0A\00"
@.str.3 = [26 x i8] c"Set port# to default: %d\0A\00"
@.str.4 = [24 x i8] c"connect to %s:%d: fail\0A\00"
@.str.5 = [19 x i8] c"connect to %s: ok\0A\00"
@.str.6 = [5 x i8] c"TX: \00"
@stdin = global i32 0
@.str.7 = [42 x i8] c"Request to send %d bytes; Sent %d bytes\0A\00"
@.str.8 = [8 x i8] c"RX: %s\0A\00"
@str = [11 x i8] c"socket: ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = alloca [64 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
store i8 72, i8* %7
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 1
store i8 101, i8* %8
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 2
store i8 108, i8* %9
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 3
store i8 108, i8* %10
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 4
store i8 111, i8* %11
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%13 = load i32, i32* @AF_INET
%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 %21
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%23 = call i32 @bzero(i8* %6, i32 24)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = icmp sgt i32 %0, 1
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i8* %12, i8* %29)
br label %31
31: ; preds = %27, %21
%32 = call %struct.hostent* @gethostbyname(i8* %12)
%33 = icmp eq %struct.hostent* %32, null
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = call i64 @inet_addr(i8* %12)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i64 %35, i64* %36
%37 = load i64, i64* @INADDR_NONE
%38 = icmp eq i64 %35, %37
br i1 %38, label %39, label %52
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %31
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i64 0, i32 1
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to i8*
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%49 = bitcast i64* %48 to i8*
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i64 0, i32 0
%51 = load i32, i32* %50
br label %52
52: ; preds = %34, %44
%53 = icmp sgt i32 %0, 2
br i1 %53, label %54, label %58
54: ; preds = %52
%55 = getelementptr inbounds i8*, i8** %1, i64 2
%56 = load i8*, i8** %55
%57 = call i32 @atoi(i8* %56)
br label %60
58: ; preds = %52
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 1100)
br label %60
60: ; preds = %58, %54
%61 = phi i32 [ %57, %54 ], [ 1100, %58 ]
%62 = call i32 @htons(i32 %61)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %62, i32* %63
%64 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%65 = call i32 @connect(i32 %15, %struct.sockaddr* %64, i64 24)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %12, i32 %61)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %60
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %12)
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @bzero(i8* %7, i32 512)
%76 = load i32, i32* @stdin
%77 = call i32 @fgets(i8* %7, i32 511, i32 %76)
%78 = call i64 @strlen(i8* %7)
%79 = call i32 @send(i32 %15, i8* %7, i64 %78, i32 0)
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i64 %78, i32 %79)
%81 = call i32 @bzero(i8* %7, i32 512)
%82 = call i64 @recv(i32 %15, i8* %7, i32 512, i32 0)
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%85 = call i32 @bzero(i8* %7, i32 512)
%86 = load i32, i32* @stdin
%87 = call i32 @fgets(i8* %7, i32 511, i32 %86)
%88 = call i64 @strlen(i8* %7)
%89 = call i32 @send(i32 %15, i8* %7, i64 %88, i32 0)
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i64 %88, i32 %89)
%91 = call i32 @bzero(i8* %7, i32 512)
%92 = call i64 @recv(i32 %15, i8* %7, i32 512, i32 0)
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%95 = call i32 @bzero(i8* %7, i32 512)
%96 = load i32, i32* @stdin
%97 = call i32 @fgets(i8* %7, i32 511, i32 %96)
%98 = call i64 @strlen(i8* %7)
%99 = call i32 @send(i32 %15, i8* %7, i64 %98, i32 0)
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i64 %98, i32 %99)
%101 = call i32 @bzero(i8* %7, i32 512)
%102 = call i64 @recv(i32 %15, i8* %7, i32 512, i32 0)
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%104 = call i32 @close(i32 %15)
ret i32 0
}