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

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ close(int);
scalar_t__ strlen(char const *);
int ui_connect(struct sockaddr *, unsigned int);
int ui_send(int, char const *, char const *);
int ui_send_to(struct sockaddr *dest, unsigned int dest_len, const char *name,
               const char *value) {
  int sock;
  int ret;
  if (strlen(name) == 0)
    return -EINVAL;
  sock = ui_connect(dest, dest_len);
  if (sock < 0)
    return sock;
  ret = ui_send(sock, name, value);
  close(sock);
  return ret;
}


x86 assembly (clang, -O0):
<ui_send_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    117d <ui_send_to+0x3d>
xor    %eax,%eax
mov    0x2e6d(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <ui_send_to+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <ui_connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11a1 <ui_send_to+0x61>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <ui_send_to+0x82>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <ui_send@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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ui_send_to>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdx)
je     1167 <ui_send_to+0x37>
mov    %rcx,%r14
mov    %rdx,%r15
call   1050 <ui_connect@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1172 <ui_send_to+0x42>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <ui_send@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%eax
jmp    1174 <ui_send_to+0x44>
mov    0x2e72(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@EINVAL = global i32 0
define i32 @ui_send_to(%struct.sockaddr* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %8
%13 = call i64 @strlen(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* @EINVAL
%17 = sub nsw i32 0, %16
store i32 %17, i32* %5
br label %34
18: ; preds = %4
%19 = load %struct.sockaddr*, %struct.sockaddr** %6
%20 = load i32, i32* %7
%21 = call i32 @ui_connect(%struct.sockaddr* %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i32, i32* %10
store i32 %25, i32* %5
br label %34
26: ; preds = %18
%27 = load i32, i32* %10
%28 = load i8*, i8** %8
%29 = load i8*, i8** %9
%30 = call i32 @ui_send(i32 %27, i8* %28, i8* %29)
store i32 %30, i32* %11
%31 = load i32, i32* %10
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %11
store i32 %33, i32* %5
br label %34
34: ; preds = %26, %24, %15
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@EINVAL = global i32 0
define i32 @ui_send_to(%struct.sockaddr* %0, i32 %1, i8* %2, i8* %3) {
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @EINVAL
%9 = sub nsw i32 0, %8
br label %16
10: ; preds = %4
%11 = tail call i32 @ui_connect(%struct.sockaddr* %0, i32 %1)
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @ui_send(i32 %11, i8* %2, i8* %3)
%15 = tail call i32 @close(i32 %11)
br label %16
16: ; preds = %10, %13, %7
%17 = phi i32 [ %9, %7 ], [ %14, %13 ], [ %11, %10 ]
ret i32 %17
}