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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int close(int);
char connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char recv(int, void *, int, int /*<<< orphan*/);
char send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strstr(char *, char *);
void My_HTTP_GET(char *http_message, int message_length) {
  int sockfd = 0;
  sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sockfd < 0) {
    perror("ERROR: Socket could not be created!");
    exit(1);
  }
  struct sockaddr_in serv_addr;
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  int result =
      inet_pton(AF_INET, "54.209.233.84", &(serv_addr.sin_addr.s_addr));
  if (result != 1) {
    perror("Error: Address is not valid!\n");
    exit(1);
  }
  serv_addr.sin_port = htons(80);
  char n = connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  if (n < 0) {
    perror("ERROR: Connection to ipinfo.io failed\n");
    exit(1);
  }
  n = send(sockfd, http_message, message_length, 0);
  if (n < 0) {
    perror("Error: Sending HTTP GET failed!");
    exit(1);
  }
  char buffer[200];
  bzero(buffer, 200);
  n = recv(sockfd, (void *)buffer, 184, 0);
  if (n == -1) {
    perror("Error: Reading 1 HTTP RESPONSE failed\n");
    exit(1);
  }
  char *index = strstr(buffer, "\r\n\r\n");
  printf("%s\n", index + 4);
  if (close(sockfd) == -1) {
    perror("Error: Socket can not be closed\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<My_HTTP_GET>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    121c <My_HTTP_GET+0x5c>
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    0xdd6(%rip),%rsi
call   1080 <inet_pton@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1276 <My_HTTP_GET+0xb6>
lea    0xdcb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0x0,%eax
jge    12ba <My_HTTP_GET+0xfa>
lea    0xda5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0x0,%eax
jge    12f1 <My_HTTP_GET+0x131>
lea    0xd95(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xf0(%rbp),%rdi
mov    $0xc8,%esi
call   10a0 <bzero@plt>
mov    -0x10(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0xb8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0xffffffff,%eax
jne    133e <My_HTTP_GET+0x17e>
lea    0xd68(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xf0(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rsi
add    $0x4,%rsi
lea    0xd59(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1396 <My_HTTP_GET+0x1d6>
lea    0xd40(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<My_HTTP_GET>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x2e0e(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12c5 <My_HTTP_GET+0x105>
mov    %eax,%ebx
mov    %rsp,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x0(%rbp),%edi
mov    %edi,0x8(%rsp)
lea    0x4(%rsp),%rdx
lea    0xe06(%rip),%rsi
call   1080 <inet_pton@plt>
cmp    $0x1,%eax
jne    12ce <My_HTTP_GET+0x10e>
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %al,%al
js     12d7 <My_HTTP_GET+0x117>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %al,%al
js     12e0 <My_HTTP_GET+0x120>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc8,%esi
call   10a0 <bzero@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xb8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xff,%al
je     12e9 <My_HTTP_GET+0x129>
lea    0xe2d(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10d0 <strstr@plt>
lea    0x4(%rax),%rsi
lea    0xe1d(%rip),%rdi
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
je     12f2 <My_HTTP_GET+0x132>
add    $0xd8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd34(%rip),%rdi
jmp    12f9 <My_HTTP_GET+0x139>
lea    0xd5d(%rip),%rdi
jmp    12f9 <My_HTTP_GET+0x139>
lea    0xd72(%rip),%rdi
jmp    12f9 <My_HTTP_GET+0x139>
lea    0xd90(%rip),%rdi
jmp    12f9 <My_HTTP_GET+0x139>
lea    0xda7(%rip),%rdi
jmp    12f9 <My_HTTP_GET+0x139>
lea    0xdce(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [36 x i8] c"ERROR: Socket could not be created!\00"
@.str.1 = [14 x i8] c"54.209.233.84\00"
@.str.2 = [30 x i8] c"Error: Address is not valid!\0A\00"
@.str.3 = [39 x i8] c"ERROR: Connection to ipinfo.io failed\0A\00"
@.str.4 = [32 x i8] c"Error: Sending HTTP GET failed!\00"
@.str.5 = [39 x i8] c"Error: Reading 1 HTTP RESPONSE failed\0A\00"
@.str.6 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [33 x i8] c"Error: Socket can not be closed\0A\00"
define void @My_HTTP_GET(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i8
%9 = alloca [200 x i8]
%10 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = load i32, i32* @IPPROTO_TCP
%14 = call i32 @socket(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = bitcast %struct.sockaddr_in* %6 to i8*
%22 = call i32 @bzero(i8* %21, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
%28 = call i32 @inet_pton(i32 %25, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %20
%32 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %20
%35 = call i32 @htons(i32 80)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %35, i32* %36
%37 = load i32, i32* %5
%38 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%39 = call signext i8 @connect(i32 %37, %struct.sockaddr* %38, i32 12)
store i8 %39, i8* %8
%40 = load i8, i8* %8
%41 = sext i8 %40 to i32
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %34
%44 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %34
%47 = load i32, i32* %5
%48 = load i8*, i8** %3
%49 = load i32, i32* %4
%50 = call signext i8 @send(i32 %47, i8* %48, i32 %49, i32 0)
store i8 %50, i8* %8
%51 = load i8, i8* %8
%52 = sext i8 %51 to i32
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %46
%55 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %46
%58 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%59 = call i32 @bzero(i8* %58, i32 200)
%60 = load i32, i32* %5
%61 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%62 = call signext i8 @recv(i32 %60, i8* %61, i32 184, i32 0)
store i8 %62, i8* %8
%63 = load i8, i8* %8
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %57
%67 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %57
%70 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%71 = call i8* @strstr(i8* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %71, i8** %10
%72 = load i8*, i8** %10
%73 = getelementptr inbounds i8, i8* %72, i64 4
%74 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %73)
%75 = load i32, i32* %5
%76 = call i32 @close(i32 %75)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %69
%79 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %69
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [36 x i8] c"ERROR: Socket could not be created!\00"
@.str.1 = [14 x i8] c"54.209.233.84\00"
@.str.2 = [30 x i8] c"Error: Address is not valid!\0A\00"
@.str.3 = [39 x i8] c"ERROR: Connection to ipinfo.io failed\0A\00"
@.str.4 = [32 x i8] c"Error: Sending HTTP GET failed!\00"
@.str.5 = [39 x i8] c"Error: Reading 1 HTTP RESPONSE failed\0A\00"
@.str.6 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [33 x i8] c"Error: Socket can not be closed\0A\00"
define void @My_HTTP_GET(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [200 x i8]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = call i32 @bzero(i8* %14, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%19 = call i32 @inet_pton(i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %13
%25 = call i32 @htons(i32 80)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call signext i8 @connect(i32 %8, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i8 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = call signext i8 @send(i32 %8, i8* %0, i32 %1, i32 0)
%35 = icmp slt i8 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %33
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%41 = call i32 @bzero(i8* %40, i32 200)
%42 = call signext i8 @recv(i32 %8, i8* %40, i32 184, i32 0)
%43 = icmp eq i8 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
%48 = call i8* @strstr(i8* %40, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%49 = getelementptr inbounds i8, i8* %48, i64 4
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %49)
%51 = call i32 @close(i32 %8)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %47
ret void
}