#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_storage {
  int dummy;
};
typedef int /*<<< orphan*/ ss;
typedef int socklen_t;

/* Variables and functions */
int socket_addr(char const *, struct sockaddr_storage *, int *);
int socket_connect_by_addr(int *, int, struct sockaddr_storage *, int);
int __attribute__((warn_unused_result))
socket_connect_by_name(int *fd, int socktype, const char *name) {
  struct sockaddr_storage ss;
  socklen_t ss_len;
  int e;
  ss_len = sizeof(ss);
  e = socket_addr(name, &ss, &ss_len);
  if (e)
    return e;
  return socket_connect_by_addr(fd, socktype, &ss, ss_len);
}


x86 assembly (clang, -O0):
<socket_connect_by_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x4,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <socket_addr@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1163 <socket_connect_by_name+0x43>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1179 <socket_connect_by_name+0x59>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%ecx
lea    -0x28(%rbp),%rdx
call   1040 <socket_connect_by_addr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_connect_by_name>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rax
mov    %esi,%ebp
mov    %rdi,%rbx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1030 <socket_addr@plt>
test   %eax,%eax
jne    115f <socket_connect_by_name+0x3f>
mov    0xc(%rsp),%ecx
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <socket_connect_by_addr@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
define i32 @socket_connect_by_name(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.sockaddr_storage
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 4, i32* %9
%11 = load i8*, i8** %7
%12 = call i32 @socket_addr(i8* %11, %struct.sockaddr_storage* %8, i32* %9)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %10
store i32 %16, i32* %4
br label %22
17: ; preds = %3
%18 = load i32*, i32** %5
%19 = load i32, i32* %6
%20 = load i32, i32* %9
%21 = call i32 @socket_connect_by_addr(i32* %18, i32 %19, %struct.sockaddr_storage* %8, i32 %20)
store i32 %21, i32* %4
br label %22
22: ; preds = %17, %15
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
define i32 @socket_connect_by_name(i32* %0, i32 %1, i8* %2) {
%4 = alloca %struct.sockaddr_storage
%5 = alloca i32
%6 = bitcast %struct.sockaddr_storage* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = call i32 @socket_addr(i8* %2, %struct.sockaddr_storage* %4, i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %5
%12 = call i32 @socket_connect_by_addr(i32* %0, i32 %1, %struct.sockaddr_storage* %4, i32 %11)
br label %13
13: ; preds = %3, %10
%14 = phi i32 [ %12, %10 ], [ %8, %3 ]
ret i32 %14
}