#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 hdhomerun_control_sock_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/
hdhomerun_control_close_sock(struct hdhomerun_control_sock_t *);
int /*<<< orphan*/
hdhomerun_control_connect_sock(struct hdhomerun_control_sock_t *);
int hdhomerun_control_get_set(struct hdhomerun_control_sock_t *, char const *,
                              char const *, char **, char **);
int hdhomerun_control_set(struct hdhomerun_control_sock_t *cs, const char *name,
                          const char *value, char **pvalue, char **perror) {
  if (!hdhomerun_control_connect_sock(cs)) {
    return -1;
  }
  int ret = hdhomerun_control_get_set(cs, name, value, pvalue, perror);
  if (ret < 0) {
    hdhomerun_control_close_sock(cs);
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<hdhomerun_control_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <hdhomerun_control_connect_sock@plt>
cmp    $0x0,%eax
jne    116a <hdhomerun_control_set+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <hdhomerun_control_set+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <hdhomerun_control_get_set@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11a5 <hdhomerun_control_set+0x75>
mov    -0x10(%rbp),%rdi
call   1050 <hdhomerun_control_close_sock@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <hdhomerun_control_set+0x7b>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdhomerun_control_set>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
call   1030 <hdhomerun_control_connect_sock@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     117d <hdhomerun_control_set+0x4d>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <hdhomerun_control_get_set@plt>
test   %eax,%eax
jns    117d <hdhomerun_control_set+0x4d>
mov    %rbx,%rdi
call   1050 <hdhomerun_control_close_sock@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hdhomerun_control_sock_t = type { i32 }
define i32 @hdhomerun_control_set(%struct.hdhomerun_control_sock_t* %0, i8* %1, i8* %2, i8** %3, i8** %4) {
%6 = alloca i32
%7 = alloca %struct.hdhomerun_control_sock_t*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i32
store %struct.hdhomerun_control_sock_t* %0, %struct.hdhomerun_control_sock_t** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
%13 = load %struct.hdhomerun_control_sock_t*, %struct.hdhomerun_control_sock_t** %7
%14 = call i32 @hdhomerun_control_connect_sock(%struct.hdhomerun_control_sock_t* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %5
store i32 -1, i32* %6
br label %31
17: ; preds = %5
%18 = load %struct.hdhomerun_control_sock_t*, %struct.hdhomerun_control_sock_t** %7
%19 = load i8*, i8** %8
%20 = load i8*, i8** %9
%21 = load i8**, i8*** %10
%22 = load i8**, i8*** %11
%23 = call i32 @hdhomerun_control_get_set(%struct.hdhomerun_control_sock_t* %18, i8* %19, i8* %20, i8** %21, i8** %22)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %17
%27 = load %struct.hdhomerun_control_sock_t*, %struct.hdhomerun_control_sock_t** %7
%28 = call i32 @hdhomerun_control_close_sock(%struct.hdhomerun_control_sock_t* %27)
store i32 -1, i32* %6
br label %31
29: ; preds = %17
%30 = load i32, i32* %12
store i32 %30, i32* %6
br label %31
31: ; preds = %29, %26, %16
%32 = load i32, i32* %6
ret i32 %32
}

LLVM IR (-O2):
%struct.hdhomerun_control_sock_t = type { i32 }
define i32 @hdhomerun_control_set(%struct.hdhomerun_control_sock_t* %0, i8* %1, i8* %2, i8** %3, i8** %4) {
%6 = tail call i32 @hdhomerun_control_connect_sock(%struct.hdhomerun_control_sock_t* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @hdhomerun_control_get_set(%struct.hdhomerun_control_sock_t* %0, i8* %1, i8* %2, i8** %3, i8** %4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @hdhomerun_control_close_sock(%struct.hdhomerun_control_sock_t* %0)
br label %13
13: ; preds = %11, %8, %5
%14 = phi i32 [ -1, %5 ], [ -1, %11 ], [ %9, %8 ]
ret i32 %14
}