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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ sockaddrfill(struct sockaddr_in *, char const *, char const *,
                        int /*<<< orphan*/, int /*<<< orphan*/, int);
int tcpstrbind(int sock, const char *hostname, const char *service) {
  struct sockaddr_in sa;
  if (sockaddrfill(&sa, hostname, service, AF_INET, SOCK_STREAM, 1) < 0) {
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tcpstrbind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    0x2ea6(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8d(%rip),%rax
mov    (%rax),%r8d
lea    -0x20(%rbp),%rdi
mov    $0x1,%r9d
call   1030 <sockaddrfill@plt>
cmp    $0x0,%rax
jge    1173 <tcpstrbind+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <tcpstrbind+0x81>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
cmp    $0x0,%rax
jge    119a <tcpstrbind+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <tcpstrbind+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcpstrbind>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%ecx
mov    0x2ea1(%rip),%rax
mov    (%rax),%r8d
lea    0x8(%rsp),%rdi
mov    $0x1,%r9d
call   1030 <sockaddrfill@plt>
test   %rax,%rax
js     1166 <tcpstrbind+0x46>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <bind@plt>
sar    $0x3f,%rax
jmp    116b <tcpstrbind+0x4b>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @tcpstrbind(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.sockaddr_in
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = load i8*, i8** %7
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i64 @sockaddrfill(%struct.sockaddr_in* %8, i8* %9, i8* %10, i32 %11, i32 %12, i32 1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %23
16: ; preds = %3
%17 = load i32, i32* %5
%18 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%19 = call i64 @bind(i32 %17, %struct.sockaddr* %18, i32 4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %4
br label %23
22: ; preds = %16
store i32 0, i32* %4
br label %23
23: ; preds = %22, %21, %15
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @tcpstrbind(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i64 @sockaddrfill(%struct.sockaddr_in* %4, i8* %1, i8* %2, i32 %6, i32 %7, i32 1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %3
%11 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%12 = call i64 @bind(i32 %0, %struct.sockaddr* %11, i32 4)
%13 = ashr i64 %12, 63
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %10, %3
%16 = phi i32 [ -1, %3 ], [ %14, %10 ]
ret i32 %16
}