#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*/ value;
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IP_TRANSPARENT;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_IP;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd;
  int value = 1;
  char buffer[1024];
  struct sockaddr_in server_addr;
  struct hostent *host;
  if (argc != 2) {
    fprintf(stderr, "Usage:%s hostname \a\n", argv[0]);
    exit(1);
  }
  if ((host = gethostbyname(argv[1])) == NULL) {
    fprintf(stderr, "Gethostname error\n");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "Socket Error:%s\a\n", strerror(errno));
    exit(1);
  }
  setsockopt(sockfd, SOL_IP, IP_TRANSPARENT, &value, sizeof(value));
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(80);
  server_addr.sin_addr = *((struct in_addr *)host->h_addr);
  if (connect(sockfd, (struct sockaddr *)(&server_addr),
              sizeof(struct sockaddr)) == -1) {
    fprintf(stderr, "Connect Error:%s\a\n", strerror(errno));
    exit(1);
  }
  write(sockfd, "hello", strlen("hello"));
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1212 <main+0x52>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jne    1251 <main+0x91>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12b4 <main+0xf4>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x43c(%rbp),%edi
mov    %rax,%rdx
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
mov    0x2d09(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x430(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x438(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x430(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1375 <main+0x1b5>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x440(%rbp)
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x440(%rbp),%edi
mov    %rax,%rdx
lea    0xcd6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    0xcc8(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    %eax,%edx
lea    0xcb4(%rip),%rsi
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x1,0x4(%rsp)
cmp    $0x2,%edi
jne    1206 <main+0x46>
mov    0x8(%rsi),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
jne    121e <main+0x5e>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xde7(%rip),%rsi
jmp    12f0 <main+0x130>
mov    %rax,%rbx
mov    0x2db8(%rip),%r15
mov    (%r15),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
jne    1263 <main+0xa3>
mov    0x2d81(%rip),%rax
mov    (%rax),%ebx
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xdca(%rip),%rsi
jmp    12eb <main+0x12b>
mov    %eax,%ebp
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1301 <main+0x141>
mov    0x2cf4(%rip),%rax
mov    (%rax),%ebx
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd4f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd45(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage:%s hostname \07\0A\00"
@.str.1 = [19 x i8] c"Gethostname error\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"Socket Error:%s\07\0A\00"
@errno = global i32 0
@SOL_IP = global i32 0
@IP_TRANSPARENT = global i32 0
@.str.3 = [19 x i8] c"Connect Error:%s\07\0A\00"
@.str.4 = [6 x i8] c"hello\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 [1024 x i8]
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call %struct.hostent* @gethostbyname(i8* %23)
store %struct.hostent* %24, %struct.hostent** %10
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i32, i32* @AF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
store i32 %33, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %30
%42 = load i32, i32* %6
%43 = load i32, i32* @SOL_IP
%44 = load i32, i32* @IP_TRANSPARENT
%45 = call i32 @setsockopt(i32 %42, i32 %43, i32 %44, i32* %7, i32 4)
%46 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %47, i32* %48
%49 = call i32 @htons(i32 80)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %49, i32* %50
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%52 = load %struct.hostent*, %struct.hostent** %10
%53 = getelementptr inbounds %struct.hostent, %struct.hostent* %52, i32 0, i32 0
%54 = load i64, i64* %53
%55 = inttoptr i64 %54 to %struct.in_addr*
%56 = bitcast %struct.in_addr* %51 to i8*
%57 = bitcast %struct.in_addr* %55 to i8*
%58 = load i32, i32* %6
%59 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%60 = call i32 @connect(i32 %58, %struct.sockaddr* %59, i32 4)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %68
62: ; preds = %41
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %41
%69 = load i32, i32* %6
%70 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%71 = call i32 @write(i32 %69, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %70)
%72 = load i32, i32* %6
%73 = call i32 @close(i32 %72)
%74 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage:%s hostname \07\0A\00"
@.str.1 = [19 x i8] c"Gethostname error\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"Socket Error:%s\07\0A\00"
@errno = global i32 0
@SOL_IP = global i32 0
@IP_TRANSPARENT = global i32 0
@.str.3 = [19 x i8] c"Connect Error:%s\07\0A\00"
@.str.4 = [6 x i8] c"hello\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call %struct.hostent* @gethostbyname(i8* %15)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %22
%34 = load i32, i32* @SOL_IP
%35 = load i32, i32* @IP_TRANSPARENT
%36 = call i32 @setsockopt(i32 %25, i32 %34, i32 %35, i32* %3, i32 4)
%37 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %38, i32* %39
%40 = call i32 @htons(i32 80)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %40, i32* %41
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to i32*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%46 = load i32, i32* %44
store i32 %46, i32* %45
%47 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%48 = call i32 @connect(i32 %25, %struct.sockaddr* %47, i32 4)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %56
50: ; preds = %33
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %33
%57 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @write(i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %57)
%59 = call i32 @close(i32 %25)
%60 = call i32 @exit(i32 0)
unreachable
}