#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__ {
  int /*<<< orphan*/ 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*/ serv_addr;
typedef int /*<<< orphan*/ s;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ _error(char *);
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  struct sharknado {
    int a;
    char b;
    float c;
  };
  struct sharknado s = {1, 'a', 2.0f};
  int sockfd, portno, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  char buffer[256];
  if (argc < 3) {
    fprintf(stderr, "usage %s hostname port\n", argv[0]);
    exit(0);
  }
  portno = atoi(argv[2]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    _error("ERROR opening socket");
  server = gethostbyname(argv[1]);
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host\n");
    exit(0);
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  serv_addr.sin_port = htons(portno);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    _error("ERROR connecting");
  n = write(sockfd, (char *)&s, sizeof(s));
  if (n < 0)
    _error("ERROR writing to socket");
  bzero(buffer, 256);
  n = read(sockfd, buffer, 255);
  if (n < 0)
    _error("ERROR reading from socket");
  printf("%s\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe10(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe0e(%rip),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    122c <main+0x5c>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    126e <main+0x9e>
lea    0xdbb(%rip),%rdi
call   1090 <_error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12a8 <main+0xd8>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
add    $0x4,%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bcopy@plt>
mov    -0x28(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    130f <main+0x13f>
lea    0xd44(%rip),%rdi
call   1090 <_error@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1339 <main+0x169>
lea    0xd2b(%rip),%rdi
call   1090 <_error@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    -0x24(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xff,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1377 <main+0x1a7>
lea    0xd05(%rip),%rdi
call   1090 <_error@plt>
lea    -0x140(%rbp),%rsi
lea    0xd0c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%rbp
mov    0xe20(%rip),%eax
mov    %eax,0x18(%rsp)
mov    0xe0d(%rip),%rax
mov    %rax,0x10(%rsp)
cmp    $0x2,%edi
jle    1318 <main+0x148>
mov    0x10(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    0x2dd4(%rip),%r12
mov    (%r12),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    123a <main+0x6a>
lea    0xdef(%rip),%rdi
call   1090 <_error@plt>
mov    0x8(%rbp),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     133a <main+0x16a>
mov    %rax,%rbp
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbp),%rsi
lea    0x4(%rsp),%rdi
mov    0x0(%rbp),%edx
call   10a0 <memmove@plt>
mov    %r14d,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
jns    12a3 <main+0xd3>
lea    0xdb0(%rip),%rdi
call   1090 <_error@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    12c4 <main+0xf4>
lea    0xda0(%rip),%rdi
call   1090 <_error@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xff,%edx
call   1060 <read@plt>
test   %eax,%eax
jns    12f5 <main+0x125>
lea    0xd87(%rip),%rdi
call   1090 <_error@plt>
lea    0xd95(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xce0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sharknado = type { i32, i8, float }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const.main.s = %struct.sharknado { i32 1, i8 97, float 2.000000e+00 }
@stderr = global i32 0
@.str = [24 x i8] c"usage %s hostname port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sharknado
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast %struct.sharknado* %6 to i8*
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %8
%28 = load i32, i32* @AF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = call i32 @_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %23
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call %struct.hostent* @gethostbyname(i8* %38)
store %struct.hostent* %39, %struct.hostent** %11
%40 = load %struct.hostent*, %struct.hostent** %11
%41 = icmp eq %struct.hostent* %40, null
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %35
%47 = bitcast %struct.sockaddr_in* %10 to i8*
%48 = call i32 @bzero(i8* %47, i32 12)
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %49, i32* %50
%51 = load %struct.hostent*, %struct.hostent** %11
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 1
%53 = load i64, i64* %52
%54 = inttoptr i64 %53 to i8*
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%56 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %55, i32 0, i32 0
%57 = bitcast i32* %56 to i8*
%58 = load %struct.hostent*, %struct.hostent** %11
%59 = getelementptr inbounds %struct.hostent, %struct.hostent* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @bcopy(i8* %54, i8* %57, i32 %60)
%62 = load i32, i32* %8
%63 = call i32 @htons(i32 %62)
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %63, i32* %64
%65 = load i32, i32* %7
%66 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%67 = call i64 @connect(i32 %65, %struct.sockaddr* %66, i32 12)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %46
%70 = call i32 @_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %71
71: ; preds = %69, %46
%72 = load i32, i32* %7
%73 = bitcast %struct.sharknado* %6 to i8*
%74 = call i32 @write(i32 %72, i8* %73, i32 12)
store i32 %74, i32* %9
%75 = load i32, i32* %9
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %71
%78 = call i32 @_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %79
79: ; preds = %77, %71
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%81 = call i32 @bzero(i8* %80, i32 256)
%82 = load i32, i32* %7
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%84 = call i32 @read(i32 %82, i8* %83, i32 255)
store i32 %84, i32* %9
%85 = load i32, i32* %9
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %79
%88 = call i32 @_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %89
89: ; preds = %87, %79
%90 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%91 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %90)
ret i32 0
}

LLVM IR (-O2):
%struct.sharknado = type { i32, i8, float }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const.main.s = %struct.sharknado { i32 1, i8 97, float 2.000000e+00 }
@stderr = global i32 0
@.str = [24 x i8] c"usage %s hostname port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sharknado
%4 = alloca %struct.sockaddr_in
%5 = alloca [256 x i8]
%6 = bitcast %struct.sharknado* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 3
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = tail call i32 @_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %15
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = tail call %struct.hostent* @gethostbyname(i8* %27)
%29 = icmp eq %struct.hostent* %28, null
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%33 = tail call i32 @exit(i32 0)
unreachable
34: ; preds = %25
%35 = call i32 @bzero(i8* %7, i32 12)
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i64 0, i32 1
%39 = load i64, i64* %38
%40 = inttoptr i64 %39 to i8*
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%42 = bitcast i32* %41 to i8*
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i64 0, i32 0
%44 = load i32, i32* %43
%45 = tail call i32 @htons(i32 %18)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %45, i32* %46
%47 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%48 = call i64 @connect(i32 %21, %struct.sockaddr* %47, i32 12)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %34
%51 = call i32 @_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50, %34
%53 = call i32 @write(i32 %21, i8* %6, i32 12)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = call i32 @bzero(i8* %8, i32 256)
%59 = call i32 @read(i32 %21, i8* %8, i32 255)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 @_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %61, %57
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %8)
ret i32 0
}