#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 /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char const *,
                           char const *);
char *gai_strerror(int);
int resolve(struct sockaddr *, int, char const *, char const *,
            int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int setbindhost(struct sockaddr *ia, int pf, const char *bindhost,
                const char *servname) {
  int n;
  if (bindhost && (strcmp(bindhost, "*") == 0))
    bindhost = NULL;
  if ((n = resolve(ia, pf, bindhost, servname, AI_PASSIVE)) != 0) {
    fprintf(stderr,
            "setbindhost: %s for %s %s"
            "\n",
            gai_strerror(n), bindhost, servname);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setbindhost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1184 <setbindhost+0x44>
mov    -0x20(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1184 <setbindhost+0x44>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    0x2e4e(%rip),%rax
mov    (%rax),%r8d
call   1030 <resolve@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     11e8 <setbindhost+0xa8>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <setbindhost+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setbindhost>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %esi,%r12d
mov    %rdi,%rbp
xor    %r15d,%r15d
test   %rdx,%rdx
je     1174 <setbindhost+0x34>
mov    %rdx,%rbx
lea    0xe9d(%rip),%rsi
mov    %rdx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
cmove  %rax,%rbx
jmp    1176 <setbindhost+0x36>
xor    %ebx,%ebx
mov    0x2e6b(%rip),%rax
mov    (%rax),%r8d
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <resolve@plt>
test   %eax,%eax
je     11c2 <setbindhost+0x82>
mov    0x2e3c(%rip),%rcx
mov    (%rcx),%ebp
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xe56(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1060 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [2 x i8] c"*\00"
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"setbindhost: %s for %s %s\0A\00"
define i32 @setbindhost(%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
store %struct.sockaddr* %0, %struct.sockaddr** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = load i8*, i8** %8
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* null, i8** %8
br label %18
18: ; preds = %17, %13, %4
%19 = load %struct.sockaddr*, %struct.sockaddr** %6
%20 = load i32, i32* %7
%21 = load i8*, i8** %8
%22 = load i8*, i8** %9
%23 = load i32, i32* @AI_PASSIVE
%24 = call i32 @resolve(%struct.sockaddr* %19, i32 %20, i8* %21, i8* %22, i32 %23)
store i32 %24, i32* %10
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = load i32, i32* %10
%29 = call i8* @gai_strerror(i32 %28)
%30 = load i8*, i8** %8
%31 = load i8*, i8** %9
%32 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30, i8* %31)
store i32 -1, i32* %5
br label %34
33: ; preds = %18
store i32 0, i32* %5
br label %34
34: ; preds = %33, %26
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [2 x i8] c"*\00"
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"setbindhost: %s for %s %s\0A\00"
define i32 @setbindhost(%struct.sockaddr* %0, i32 %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %2, null
br i1 %5, label %10, label %6
6: ; preds = %4
%7 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i8* null, i8* %2
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ null, %4 ], [ %9, %6 ]
%12 = load i32, i32* @AI_PASSIVE
%13 = tail call i32 @resolve(%struct.sockaddr* %0, i32 %1, i8* %11, i8* %3, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i8* @gai_strerror(i32 %13)
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %11, i8* %3)
br label %19
19: ; preds = %10, %15
%20 = phi i32 [ -1, %15 ], [ 0, %10 ]
ret i32 %20
}