#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__ {
  void *s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
void *AF_INET;
void *INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int const);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ file_message(char *, char const *);
void *htons(int);
void *inet_addr(char const *);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strerror(int /*<<< orphan*/);
int strlen(char const *);
int /*<<< orphan*/ warning(char *);
void send_message(int port, const char *addr, const char *msg) {
  int sock;
  int rc;
  char buf[1024];
  struct sockaddr_in client;
  struct sockaddr_in server;
  const int sa_sz = sizeof(struct sockaddr_in);
  client.sin_family = AF_INET;
  client.sin_addr.s_addr = INADDR_ANY;
  client.sin_port = INADDR_ANY;
  server.sin_family = AF_INET;
  if (addr == 0)
    addr = "127.0.0.1";
  server.sin_addr.s_addr = inet_addr(addr);
  server.sin_port = htons(port);
  file_message("Creating socket", addr);
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    fatal((char *)strerror(errno));
  if (connect(sock, (struct sockaddr *)&server, sa_sz) == -1)
    fatal((char *)strerror(errno));
  if (msg == 0)
    msg = "GET / HTTP/1.0\r\n\r\n";
  int msg_sz = strlen(msg) + 1;
  if (send(sock, "GET / HTTP/1.0\r\n\r\n", msg_sz, 0) == -1)
    fatal((char *)strerror(errno));
  while ((rc = recv(sock, buf, 1024, 0)))
    printf(buf);
  if (rc == -1)
    warning((char *)strerror(errno));
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x18,-0x454(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x428(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x430(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x438(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123a <send_message+0x7a>
lea    0xdca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %rax,-0x448(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <htons@plt>
mov    %rax,-0x450(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xda6(%rip),%rdi
call   10a0 <file_message@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%rdi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    12a5 <send_message+0xe5>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rdi
call   10d0 <fatal@plt>
mov    -0x1c(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x18,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12d8 <send_message+0x118>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rdi
call   10d0 <fatal@plt>
cmpq   $0x0,-0x18(%rbp)
jne    12ee <send_message+0x12e>
lea    0xd30(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x458(%rbp),%edx
lea    0xd0a(%rip),%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
jne    1336 <send_message+0x176>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rdi
call   10d0 <fatal@plt>
jmp    133b <send_message+0x17b>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     136e <send_message+0x1ae>
lea    -0x420(%rbp),%rdi
call   1080 <printf@plt>
jmp    133b <send_message+0x17b>
cmpl   $0xffffffff,-0x20(%rbp)
jne    138e <send_message+0x1ce>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rdi
call   1040 <warning@plt>
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x428,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e1c(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
test   %rsi,%rsi
lea    0xe22(%rip),%rax
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1080 <inet_addr@plt>
mov    %rax,0x10(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %rax,0x8(%rsp)
lea    0xe08(%rip),%rdi
mov    %rbx,%rsi
call   1090 <file_message@plt>
mov    (%r15),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    123a <send_message+0x8a>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rdi
call   10c0 <fatal@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1266 <send_message+0xb6>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rdi
call   10c0 <fatal@plt>
test   %r14,%r14
lea    0xdaa(%rip),%rbx
cmove  %rbx,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
jne    12a6 <send_message+0xf6>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rdi
call   10c0 <fatal@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     12ed <send_message+0x13d>
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jne    12d0 <send_message+0x120>
add    $0x428,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i8* null
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [16 x i8] c"Creating socket\00"
@SOCK_STREAM = global i32 0
@errno = global i32 0
@.str.2 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
define void @send_message(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 24, i32* %12
%14 = load i8*, i8** @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i8* %14, i8** %15
%16 = load i8*, i8** @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i8* %16, i8** %18
%19 = load i8*, i8** @INADDR_ANY
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i8* %19, i8** %20
%21 = load i8*, i8** @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %21, i8** %22
%23 = load i8*, i8** %5
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
br label %26
26: ; preds = %25, %3
%27 = load i8*, i8** %5
%28 = call i8* @inet_addr(i8* %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i8* %28, i8** %30
%31 = load i32, i32* %4
%32 = call i8* @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i8* %32, i8** %33
%34 = load i8*, i8** %5
%35 = call i32 @file_message(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** @AF_INET
%37 = load i32, i32* @SOCK_STREAM
%38 = call i32 @socket(i8* %36, i32 %37, i32 0)
store i32 %38, i32* %7
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %45
40: ; preds = %26
%41 = load i32, i32* @errno
%42 = call i64 @strerror(i32 %41)
%43 = inttoptr i64 %42 to i8*
%44 = call i32 @fatal(i8* %43)
br label %45
45: ; preds = %40, %26
%46 = load i32, i32* %7
%47 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%48 = call i32 @connect(i32 %46, %struct.sockaddr* %47, i32 24)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = load i32, i32* @errno
%52 = call i64 @strerror(i32 %51)
%53 = inttoptr i64 %52 to i8*
%54 = call i32 @fatal(i8* %53)
br label %55
55: ; preds = %50, %45
%56 = load i8*, i8** %6
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %59
58: ; preds = %55
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %59
59: ; preds = %58, %55
%60 = load i8*, i8** %6
%61 = call i32 @strlen(i8* %60)
%62 = add nsw i32 %61, 1
store i32 %62, i32* %13
%63 = load i32, i32* %7
%64 = load i32, i32* %13
%65 = call i32 @send(i32 %63, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %64, i32 0)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %72
67: ; preds = %59
%68 = load i32, i32* @errno
%69 = call i64 @strerror(i32 %68)
%70 = inttoptr i64 %69 to i8*
%71 = call i32 @fatal(i8* %70)
br label %72
72: ; preds = %67, %59
br label %73
73: ; preds = %78, %72
%74 = load i32, i32* %7
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%76 = call i32 @recv(i32 %74, i8* %75, i32 1024, i32 0)
store i32 %76, i32* %8
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%80 = call i32 @printf(i8* %79)
br label %73
81: ; preds = %73
%82 = load i32, i32* %8
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %89
84: ; preds = %81
%85 = load i32, i32* @errno
%86 = call i64 @strerror(i32 %85)
%87 = inttoptr i64 %86 to i8*
%88 = call i32 @warning(i8* %87)
br label %89
89: ; preds = %84, %81
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i8* null
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [16 x i8] c"Creating socket\00"
@SOCK_STREAM = global i32 0
@errno = global i32 0
@.str.2 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
define void @send_message(i32 %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = load i8*, i8** @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i8* %8, i8** %9
%10 = icmp eq i8* %1, null
%11 = select i1 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %1
%12 = tail call i8* @inet_addr(i8* %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i8* %12, i8** %13
%14 = tail call i8* @htons(i32 %0)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i8* %14, i8** %15
%16 = tail call i32 @file_message(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%17 = load i8*, i8** @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i8* %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = load i32, i32* @errno
%23 = tail call i64 @strerror(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @fatal(i8* %24)
br label %26
26: ; preds = %21, %3
%27 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%28 = call i32 @connect(i32 %19, %struct.sockaddr* %27, i32 24)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* @errno
%32 = call i64 @strerror(i32 %31)
%33 = inttoptr i64 %32 to i8*
%34 = call i32 @fatal(i8* %33)
br label %35
35: ; preds = %30, %26
%36 = icmp eq i8* %2, null
%37 = select i1 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %2
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %38, 1
%40 = call i32 @send(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 0)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %47
42: ; preds = %35
%43 = load i32, i32* @errno
%44 = call i64 @strerror(i32 %43)
%45 = inttoptr i64 %44 to i8*
%46 = call i32 @fatal(i8* %45)
br label %47
47: ; preds = %42, %35
%48 = call i32 @recv(i32 %19, i8* %6, i32 1024, i32 0)
%49 = icmp eq i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %47, %50
%51 = call i32 @printf(i8* %6)
%52 = call i32 @recv(i32 %19, i8* %6, i32 1024, i32 0)
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %50
54: ; preds = %50, %47
ret void
}