#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 */
typedef int /*<<< orphan*/ u_int;
struct sockaddr_in6 {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr6;

/* Variables and functions */
int connect(int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ err_msg(char *);
int /*<<< orphan*/ memcpy(struct sockaddr_in6 *, struct sockaddr_in6 *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv_msg(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ send_msg(int /*<<< orphan*/, char *);
void get_http_ipv6(const u_int *fd, struct sockaddr_in6 *saddr6, char *buff) {
  u_int nrecv;
  u_int trx_fd = *fd;
  struct sockaddr_in6 addr6;
  memcpy(&addr6, saddr6, sizeof(*saddr6));
  if (connect(trx_fd, (struct sockaddr *)&addr6, sizeof(addr6)) == -1)
    err_msg("connect()");
  else {
    printf("Connect success\n");
    send_msg(trx_fd, buff);
    while ((nrecv = recv_msg(trx_fd, buff, 2000)) > 0) {
      printf("%s", buff);
      memset(buff, 0, 2000);
    }
  }
}


x86 assembly (clang, -O0):
<get_http_ipv6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    11ca <get_http_ipv6+0x5a>
lea    0xe40(%rip),%rdi
call   1080 <err_msg@plt>
jmp    122d <get_http_ipv6+0xbd>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <send_msg@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x7d0,%edx
call   1030 <recv_msg@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1228 <get_http_ipv6+0xb8>
mov    -0x18(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1050 <memset@plt>
jmp    11e4 <get_http_ipv6+0x74>
jmp    122d <get_http_ipv6+0xbd>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_http_ipv6>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    (%rdi),%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
je     1221 <get_http_ipv6+0xa1>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <send_msg@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x7d0,%edx
call   1040 <recv_msg@plt>
test   %eax,%eax
jle    122d <get_http_ipv6+0xad>
lea    0xe27(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x7d0,%edx
call   1040 <recv_msg@plt>
test   %eax,%eax
jg     11f0 <get_http_ipv6+0x70>
jmp    122d <get_http_ipv6+0xad>
lea    0xdd8(%rip),%rdi
call   1090 <err_msg@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"connect()\00"
@.str.1 = [17 x i8] c"Connect success\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @get_http_ipv6(i32* %0, %struct.sockaddr_in6* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca %struct.sockaddr_in6*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in6
store i32* %0, i32** %4
store %struct.sockaddr_in6* %1, %struct.sockaddr_in6** %5
store i8* %2, i8** %6
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
store i32 %11, i32* %8
%12 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%13 = call i32 @memcpy(%struct.sockaddr_in6* %9, %struct.sockaddr_in6* %12, i32 4)
%14 = load i32, i32* %8
%15 = bitcast %struct.sockaddr_in6* %9 to %struct.sockaddr*
%16 = call i32 @connect(i32 %14, %struct.sockaddr* %15, i32 4)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 @err_msg(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %36
20: ; preds = %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* %8
%23 = load i8*, i8** %6
%24 = call i32 @send_msg(i32 %22, i8* %23)
br label %25
25: ; preds = %30, %20
%26 = load i32, i32* %8
%27 = load i8*, i8** %6
%28 = call i32 @recv_msg(i32 %26, i8* %27, i32 2000)
store i32 %28, i32* %7
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %6
%34 = call i32 @memset(i8* %33, i32 0, i32 2000)
br label %25
35: ; preds = %25
br label %36
36: ; preds = %35, %18
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"connect()\00"
@.str.2 = [3 x i8] c"%s\00"
@str = [16 x i8] c"Connect success\00"
define void @get_http_ipv6(i32* nocapture %0, %struct.sockaddr_in6* %1, i8* %2) {
%4 = alloca %struct.sockaddr_in6
%5 = load i32, i32* %0
%6 = bitcast %struct.sockaddr_in6* %4 to i8*
%7 = call i32 @memcpy(%struct.sockaddr_in6* %4, %struct.sockaddr_in6* %1, i32 4)
%8 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%9 = call i32 @connect(i32 %5, %struct.sockaddr* %8, i32 4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @err_msg(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %23
13: ; preds = %3
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%15 = call i32 @send_msg(i32 %5, i8* %2)
%16 = call i32 @recv_msg(i32 %5, i8* %2, i32 2000)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13, %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%20 = call i32 @memset(i8* %2, i32 0, i32 2000)
%21 = call i32 @recv_msg(i32 %5, i8* %2, i32 2000)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %18, label %23
23: ; preds = %18, %13, %11
ret void
}