#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;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ malloc(int);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
char *make_request(char *a) {
  int sockfd, portno, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  char buffer[4096], *reply, *buffer1;
  portno = 5000;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR !! Opening Socket");
  server = gethostbyname("localhost");
  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");
  bzero(buffer, 4096);
  strcpy(buffer, a);
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0)
    error("ERROR !! writing to socket");
  reply = (char *)malloc(4096);
  bzero(reply, 4096);
  n = read(sockfd, reply, 4096);
  return reply;
}


x86 assembly (clang, -O0):
<make_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1388,-0x10(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1228 <make_request+0x48>
lea    0xddd(%rip),%rdi
call   10c0 <error@plt>
lea    0xde9(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125f <make_request+0x7f>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
mov    -0x10(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    12c6 <make_request+0xe6>
lea    0xd79(%rip),%rdi
call   10c0 <error@plt>
lea    -0x1030(%rbp),%rdi
mov    $0x1000,%esi
call   10d0 <bzero@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x104c(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1048(%rbp)
lea    -0x1030(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x104c(%rbp),%edi
mov    -0x1048(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1337 <make_request+0x157>
lea    0xd1c(%rip),%rdi
call   10c0 <error@plt>
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x1038(%rbp)
mov    -0x1038(%rbp),%rdi
mov    $0x1000,%esi
call   10d0 <bzero@plt>
mov    -0xc(%rbp),%edi
mov    -0x1038(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x1038(%rbp),%rax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_request>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    %rdi,%r14
mov    0x2def(%rip),%r12
mov    (%r12),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    121f <make_request+0x3f>
lea    0xde6(%rip),%rdi
call   10c0 <error@plt>
lea    0xdf2(%rip),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     1309 <make_request+0x129>
mov    %rax,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdi
mov    (%rbx),%edx
call   10b0 <memmove@plt>
mov    $0x1388,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
jns    128c <make_request+0xac>
lea    0xdb3(%rip),%rdi
call   10c0 <error@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   10d0 <bzero@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    12cd <make_request+0xed>
lea    0xd86(%rip),%rdi
call   10c0 <error@plt>
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1000,%esi
call   10d0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %rbx,%rax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xd09(%rip),%rsi
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"ERROR !! Opening Socket\00"
@.str.1 = [10 x i8] c"localhost\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"ERROR !! no such host \0A\00"
@.str.3 = [20 x i8] c"ERROR !! Connecting\00"
@.str.4 = [27 x i8] c"ERROR !! writing to socket\00"
define i8* @make_request(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %2
store i32 5000, i32* %4
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
%19 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store %struct.hostent* %19, %struct.hostent** %7
%20 = load %struct.hostent*, %struct.hostent** %7
%21 = icmp eq %struct.hostent* %20, null
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %18
%27 = bitcast %struct.sockaddr_in* %6 to i8*
%28 = call i32 @bzero(i8* %27, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %29, i32* %30
%31 = load %struct.hostent*, %struct.hostent** %7
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 1
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to i8*
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
%37 = bitcast i32* %36 to i8*
%38 = load %struct.hostent*, %struct.hostent** %7
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @bcopy(i8* %34, i8* %37, i32 %40)
%42 = load i32, i32* %4
%43 = call i32 @htons(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %43, i32* %44
%45 = load i32, i32* %3
%46 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%47 = call i64 @connect(i32 %45, %struct.sockaddr* %46, i32 12)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %26
%50 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %26
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%53 = call i32 @bzero(i8* %52, i32 4096)
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%55 = load i8*, i8** %2
%56 = call i32 @strcpy(i8* %54, i8* %55)
%57 = load i32, i32* %3
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = call i32 @write(i32 %57, i8* %58, i32 %60)
store i32 %61, i32* %5
%62 = load i32, i32* %5
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %51
%65 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %64, %51
%67 = call i64 @malloc(i32 4096)
%68 = inttoptr i64 %67 to i8*
store i8* %68, i8** %9
%69 = load i8*, i8** %9
%70 = call i32 @bzero(i8* %69, i32 4096)
%71 = load i32, i32* %3
%72 = load i8*, i8** %9
%73 = call i32 @read(i32 %71, i8* %72, i32 4096)
store i32 %73, i32* %5
%74 = load i8*, i8** %9
ret i8* %74
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"ERROR !! Opening Socket\00"
@.str.1 = [10 x i8] c"localhost\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"ERROR !! no such host \0A\00"
@.str.3 = [20 x i8] c"ERROR !! Connecting\00"
@.str.4 = [27 x i8] c"ERROR !! writing to socket\00"
define i8* @make_request(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca [4096 x i8]
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %12
%20 = call i32 @bzero(i8* %4, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to i8*
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%27 = bitcast i32* %26 to i8*
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%29 = load i32, i32* %28
%30 = tail call i32 @htons(i32 5000)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%33 = call i64 @connect(i32 %8, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %19
%36 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %19
%38 = call i32 @bzero(i8* %5, i32 4096)
%39 = call i32 @strcpy(i8* %5, i8* %0)
%40 = call i32 @strlen(i8* %5)
%41 = call i32 @write(i32 %8, i8* %5, i32 %40)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
%46 = call i64 @malloc(i32 4096)
%47 = inttoptr i64 %46 to i8*
%48 = call i32 @bzero(i8* %47, i32 4096)
%49 = call i32 @read(i32 %8, i8* %47, i32 4096)
ret i8* %47
}