#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int create_socket_stream(char const *, char const *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int create_tcp_server(const char *hostname, const char *servname) {
  int socket;
  if ((socket = create_socket_stream(hostname, servname)) < 0)
    return -1;
  if (listen(socket, 8) < 0) {
    perror("listen");
    close(socket);
    return -1;
  }
  return socket;
}


x86 assembly (clang, -O0):
<create_tcp_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <create_socket_stream@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1175 <create_tcp_server+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <create_tcp_server+0x72>
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1040 <listen@plt>
cmp    $0x0,%rax
jge    11ac <create_tcp_server+0x6c>
lea    0xe6d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <create_tcp_server+0x72>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_tcp_server>:
push   %rbp
push   %rbx
push   %rax
call   1060 <create_socket_stream@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1166 <create_tcp_server+0x26>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x8,%esi
call   1040 <listen@plt>
test   %rax,%rax
js     116f <create_tcp_server+0x2f>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
mov    %ebp,%edi
call   1030 <close@plt>
jmp    1166 <create_tcp_server+0x26>

LLVM IR (-O0):
@.str = [7 x i8] c"listen\00"
define i32 @create_tcp_server(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = call i32 @create_socket_stream(i8* %7, i8* %8)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %22
12: ; preds = %2
%13 = load i32, i32* %6
%14 = call i64 @listen(i32 %13, i32 8)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
store i32 -1, i32* %3
br label %22
20: ; preds = %12
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %22
22: ; preds = %20, %16, %11
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [7 x i8] c"listen\00"
define i32 @create_tcp_server(i8* %0, i8* %1) {
%3 = tail call i32 @create_socket_stream(i8* %0, i8* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @listen(i32 %3, i32 8)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @close(i32 %3)
br label %11
11: ; preds = %5, %2, %8
%12 = phi i32 [ -1, %8 ], [ -1, %2 ], [ %3, %5 ]
ret i32 %12
}