#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int __rtinfo_internal_hddtemp_connect() {
  int sockfd = -1, connresult;
  struct sockaddr_in server_addr;
  struct hostent *he;
  if ((he = gethostbyname("127.0.0.1")) == NULL) {
    if (0) {
      perror("[-] librtinfo: hddtemp gethostbyname");
    };
    return -1;
  }
  bcopy(he->h_addr, &server_addr.sin_addr, he->h_length);
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(7634);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    if (0) {
      perror("[-] librtinfo: hddtemp socket");
    };
    return -1;
  }
  connresult =
      connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr));
  if (connresult < 0) {
    if (0) {
      perror("[-] librtinfo: hddtemp connect");
    };
    close(sockfd);
    return -1;
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<__rtinfo_internal_hddtemp_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1195 <__rtinfo_internal_hddtemp_connect+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1232 <__rtinfo_internal_hddtemp_connect+0xd2>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x18(%rbp),%rsi
add    $0x8,%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x1dd2,%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11fa <__rtinfo_internal_hddtemp_connect+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1232 <__rtinfo_internal_hddtemp_connect+0xd2>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    122c <__rtinfo_internal_hddtemp_connect+0xcc>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1232 <__rtinfo_internal_hddtemp_connect+0xd2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__rtinfo_internal_hddtemp_connect>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe93(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11e0 <__rtinfo_internal_hddtemp_connect+0x80>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    0x10(%rsp),%rsi
call   1060 <bcopy@plt>
mov    0x2e56(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    $0x1dd2,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11e0 <__rtinfo_internal_hddtemp_connect+0x80>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1070 <connect@plt>
test   %eax,%eax
js     11d9 <__rtinfo_internal_hddtemp_connect+0x79>
mov    %ebp,%ebx
jmp    11e0 <__rtinfo_internal_hddtemp_connect+0x80>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @__rtinfo_internal_hddtemp_connect() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.hostent*
store i32 -1, i32* %2
%6 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %6, %struct.hostent** %5
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %39
9: ; preds = %0
%10 = load %struct.hostent*, %struct.hostent** %5
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
%14 = load %struct.hostent*, %struct.hostent** %5
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @bcopy(i32 %12, i32* %13, i32 %16)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %18, i32* %19
%20 = call i32 @htons(i32 7634)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %9
store i32 -1, i32* %1
br label %39
28: ; preds = %9
%29 = load i32, i32* %2
%30 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%31 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 12)
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
store i32 -1, i32* %1
br label %39
37: ; preds = %28
%38 = load i32, i32* %2
store i32 %38, i32* %1
br label %39
39: ; preds = %37, %34, %27, %8
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @__rtinfo_internal_hddtemp_connect() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %26, label %5
5: ; preds = %0
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @bcopy(i32 %7, i32* %8, i32 %10)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @htons(i32 7634)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %5
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i32 @connect(i32 %18, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @close(i32 %18)
br label %26
26: ; preds = %20, %5, %0, %24
%27 = phi i32 [ -1, %24 ], [ -1, %0 ], [ -1, %5 ], [ %18, %20 ]
ret i32 %27
}