#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*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ get_ip_addr(char const *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *, char const *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void send_request(char const *url, char const *domain, int *re_socket,
                  int port) {
  char header[2048];
  char ip_addr[16] = {0};
  sprintf(header,
          "GET %s HTTP/1.1\r\n"
          "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/"
          "webp,*/*;q=0.8\r\n"
          "User-Agent:%s\r\n"
          "Host:%s\r\n"
          "Connection:close\r\n"
          "\r\n",
          url, "burning/1.0", domain);
  get_ip_addr(domain, ip_addr);
  printf("IP:%s\n ", ip_addr);
  int client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  *re_socket = client_socket;
  if (client_socket < 0) {
    printf("invalid socket descriptor: %d\n", client_socket);
    exit(-1);
  }
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr(ip_addr);
  addr.sin_port = htons(port);
  int res = connect(client_socket, (struct sockaddr *)&addr, sizeof(addr));
  if (res == -1) {
    printf("connect failed,return %d.\n", res);
    exit(-1);
  }
  write(client_socket, header, strlen(header));
}


x86 assembly (clang, -O0):
<send_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%r8
lea    0xe0d(%rip),%rsi
lea    0xe97(%rip),%rcx
call   10a0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   1080 <get_ip_addr@plt>
lea    -0x830(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x834(%rbp)
mov    -0x834(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x834(%rbp)
jge    1281 <send_request+0xd1>
mov    -0x834(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    -0x840(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x838(%rbp)
lea    -0x830(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x83c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x840(%rbp)
mov    -0x834(%rbp),%edi
lea    -0x840(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
mov    %eax,-0x844(%rbp)
cmpl   $0xffffffff,-0x844(%rbp)
jne    130b <send_request+0x15b>
mov    -0x844(%rbp),%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x834(%rbp),%eax
mov    %eax,-0x854(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x850(%rbp)
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x854(%rbp),%edi
mov    -0x850(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_request>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x820,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rdx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe26(%rip),%rsi
lea    0xeb0(%rip),%rcx
lea    0x20(%rsp),%rdi
mov    %rbp,%r8
call   10a0 <sprintf@plt>
lea    0x10(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <get_ip_addr@plt>
lea    0xe98(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dd2(%rip),%r12
mov    (%r12),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    %eax,(%r15)
test   %eax,%eax
js     12aa <send_request+0xfa>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
lea    0x10(%rsp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
je     12b5 <send_request+0x105>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x820,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf4(%rip),%rdi
mov    %ebp,%esi
jmp    12c1 <send_request+0x111>
lea    0xe08(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%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 }
@.str = [145 x i8] c"GET %s HTTP/1.1\0D\0AAccept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\0D\0AUser-Agent:%s\0D\0AHost:%s\0D\0AConnection:close\0D\0A\0D\0A\00"
@.str.1 = [12 x i8] c"burning/1.0\00"
@.str.2 = [8 x i8] c"IP:%s\0A \00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [31 x i8] c"invalid socket descriptor: %d\0A\00"
@.str.4 = [27 x i8] c"connect failed,return %d.\0A\00"
define void @send_request(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [2048 x i8]
%10 = alloca [16 x i8]
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%14 = bitcast [16 x i8]* %10 to i8*
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %6
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%21 = call i32 @get_ip_addr(i8* %19, i8* %20)
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = load i32, i32* @IPPROTO_TCP
%27 = call i32 @socket(i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = load i32*, i32** %7
store i32 %28, i32* %29
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %4
%33 = load i32, i32* %11
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %4
%37 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %38, i32* %39
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%41 = call i32 @inet_addr(i8* %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = load i32, i32* %8
%45 = call i32 @htons(i32 %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %45, i32* %46
%47 = load i32, i32* %11
%48 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%49 = call i32 @connect(i32 %47, %struct.sockaddr* %48, i32 12)
store i32 %49, i32* %13
%50 = load i32, i32* %13
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %36
%53 = load i32, i32* %13
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %36
%57 = load i32, i32* %11
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%59 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = call i32 @write(i32 %57, i8* %58, i32 %60)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [145 x i8] c"GET %s HTTP/1.1\0D\0AAccept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\0D\0AUser-Agent:%s\0D\0AHost:%s\0D\0AConnection:close\0D\0A\0D\0A\00"
@.str.1 = [12 x i8] c"burning/1.0\00"
@.str.2 = [8 x i8] c"IP:%s\0A \00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [31 x i8] c"invalid socket descriptor: %d\0A\00"
@.str.4 = [27 x i8] c"connect failed,return %d.\0A\00"
define void @send_request(i8* %0, i8* %1, i32* nocapture writeonly %2, i32 %3) {
%5 = alloca [2048 x i8]
%6 = alloca [16 x i8]
%7 = alloca %struct.sockaddr_in
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%10 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%11 = call i32 @get_ip_addr(i8* %1, i8* %9)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = load i32, i32* @IPPROTO_TCP
%16 = call i32 @socket(i32 %13, i32 %14, i32 %15)
store i32 %16, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %4
%22 = bitcast %struct.sockaddr_in* %7 to i8*
%23 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @inet_addr(i8* %9)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = call i32 @htons(i32 %3)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i32 @connect(i32 %16, %struct.sockaddr* %30, i32 12)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 -1)
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %21
%37 = call i32 @strlen(i8* %8)
%38 = call i32 @write(i32 %16, i8* %8, i32 %37)
ret void
}