#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ hostname;
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  char c;
  FILE *fp;
  char hostname[64];
  int ii, s;
  struct hostent *hp;
  struct sockaddr_in sin;
  char buff[1000];
  gethostname(hostname, sizeof(hostname));
  if ((hp = gethostbyname(hostname)) == NULL) {
    fprintf(stderr, "%s: unknown host.\n", hostname);
    exit(1);
  }
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("client:  socket");
    exit(1);
  }
  sin.sin_family = AF_INET;
  sin.sin_port = htons(1234);
  bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
  if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    perror("client:  connect");
    exit(1);
  }
  ii = recv(s, buff, sizeof(buff), 0);
  if (ii > -1) {
    printf("Received %d bytes.\n", ii);
  } else {
    printf("Error, didn't receive any data.\n");
  }
  shutdown(s, 2);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
call   10b0 <gethostname@plt>
lea    -0x50(%rbp),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    121a <main+0x5a>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rdx
lea    0xdf5(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x58(%rbp)
cmp    $0x0,%eax
jge    1255 <main+0x95>
lea    0xdcd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x60(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x70(%rbp),%rsi
mov    -0x60(%rbp),%rax
mov    (%rax),%edx
call   1090 <bcopy@plt>
mov    -0x58(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    12b5 <main+0xf5>
lea    0xd7d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x58(%rbp),%edi
lea    -0x460(%rbp),%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jle    12ee <main+0x12e>
mov    -0x54(%rbp),%esi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12fc <main+0x13c>
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x58(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x440,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   10c0 <gethostname@plt>
mov    %rbx,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
jne    121e <main+0x4e>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %rax,%rbx
mov    0x2dc0(%rip),%r14
mov    (%r14),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
jns    1248 <main+0x78>
lea    0xdcd(%rip),%rdi
jmp    128a <main+0xba>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edx
mov    0x4(%rbx),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10a0 <bcopy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
jns    1299 <main+0xc9>
lea    0xd99(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0x50(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     12c2 <main+0xf2>
lea    0xd7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12ce <main+0xfe>
lea    0xd7f(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"%s: unknown host.\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"client: socket\00"
@.str.2 = [17 x i8] c"client: connect\00"
@.str.3 = [20 x i8] c"Received %d bytes.\0A\00"
@.str.4 = [33 x i8] c"Error, didn't receive any data.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32*
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca [1000 x i8]
store i32 0, i32* %1
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%11 = call i32 @gethostname(i8* %10, i32 64)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%13 = call %struct.hostent* @gethostbyname(i8* %12)
store %struct.hostent* %13, %struct.hostent** %7
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %20
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %29, i32* %30
%31 = call i32 @htons(i32 1234)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %31, i32* %32
%33 = load %struct.hostent*, %struct.hostent** %7
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%37 = load %struct.hostent*, %struct.hostent** %7
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @bcopy(i32 %35, i32* %36, i32 %39)
%41 = load i32, i32* %6
%42 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%43 = call i64 @connect(i32 %41, %struct.sockaddr* %42, i32 12)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %28
%46 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %28
%49 = load i32, i32* %6
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%51 = call i32 @recv(i32 %49, i8* %50, i32 1000, i32 0)
store i32 %51, i32* %5
%52 = load i32, i32* %5
%53 = icmp sgt i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i32, i32* %5
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %55)
br label %59
57: ; preds = %48
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %54
%60 = load i32, i32* %6
%61 = call i32 @shutdown(i32 %60, i32 2)
%62 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"%s: unknown host.\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"client: socket\00"
@.str.2 = [17 x i8] c"client: connect\00"
@.str.3 = [20 x i8] c"Received %d bytes.\0A\00"
@str = [32 x i8] c"Error, didn't receive any data.\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = call i32 @gethostname(i8* %4, i32 64)
%8 = call %struct.hostent* @gethostbyname(i8* %4)
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %4)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 1234)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @bcopy(i32 %28, i32* %29, i32 %31)
%33 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%34 = call i64 @connect(i32 %17, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %22
%37 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %22
%40 = call i32 @recv(i32 %17, i8* %6, i32 1000, i32 0)
%41 = icmp sgt i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %46
44: ; preds = %39
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
%47 = call i32 @shutdown(i32 %17, i32 2)
%48 = call i32 @exit(i32 0)
unreachable
}