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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int hddtemp_read(int, char *, size_t);
int /*<<< orphan*/ message(int /*<<< orphan*/, char *, char const *, int,
                           int /*<<< orphan*/);
int socket_open(char const *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int hddtemp_connect(const char *host, int port, char *buffer, size_t size) {
  int socket, ret;
  socket = socket_open(host, port);
  if (socket < 0) {
    message(0, "[hddtemp] Error accessing %s:%d: %s", host, port,
            strerror(errno));
    return -1;
  }
  ret = hddtemp_read(socket, buffer, size);
  close(socket);
  return ret;
}


x86 assembly (clang, -O0):
<hddtemp_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <socket_open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11c0 <hddtemp_connect+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
xor    %edi,%edi
lea    0xe51(%rip),%rsi
call   1030 <message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <hddtemp_connect+0x91>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <hddtemp_read@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hddtemp_connect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%rbx
call   1050 <socket_open@plt>
test   %eax,%eax
js     1189 <hddtemp_connect+0x39>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <hddtemp_read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
jmp    11b3 <hddtemp_connect+0x63>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe62(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %r12d,%ecx
mov    %eax,%r8d
call   1030 <message@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"[hddtemp] Error accessing %s:%d: %s\00"
@errno = global i32 0
define i32 @hddtemp_connect(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = call i32 @socket_open(i8* %12, i32 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @message(i32 0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %19, i32 %21)
store i32 -1, i32* %5
br label %31
23: ; preds = %4
%24 = load i32, i32* %10
%25 = load i8*, i8** %8
%26 = load i64, i64* %9
%27 = call i32 @hddtemp_read(i32 %24, i8* %25, i64 %26)
store i32 %27, i32* %11
%28 = load i32, i32* %10
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %11
store i32 %30, i32* %5
br label %31
31: ; preds = %23, %17
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@.str = [36 x i8] c"[hddtemp] Error accessing %s:%d: %s\00"
@errno = global i32 0
define i32 @hddtemp_connect(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = tail call i32 @socket_open(i8* %0, i32 %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @message(i32 0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %9)
br label %14
11: ; preds = %4
%12 = tail call i32 @hddtemp_read(i32 %5, i8* %2, i64 %3)
%13 = tail call i32 @close(i32 %5)
br label %14
14: ; preds = %11, %7
%15 = phi i32 [ -1, %7 ], [ %12, %11 ]
ret i32 %15
}