#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int create_socket(uint16_t port) {
  int sock;
  struct sockaddr_in name;
  sock = socket(PF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    syslog(LOG_ERR, "Could not create socket");
  }
  name.sin_family = AF_INET;
  name.sin_port = htons(port);
  name.sin_addr.s_addr = INADDR_ANY;
  if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0) {
    syslog(LOG_ERR, "Error binding socket name");
  }
  return sock;
}


x86 assembly (clang, -O0):
<create_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1186 <create_socket+0x46>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1040 <syslog@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    11d9 <create_socket+0x99>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1040 <syslog@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_socket>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    117c <create_socket+0x3c>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <syslog@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1050 <bind@plt>
test   %rax,%rax
jns    11cc <create_socket+0x8c>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1040 <syslog@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [26 x i8] c"Error binding socket name\00"
define i32 @create_socket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @LOG_ERR
%12 = call i32 @syslog(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* %2
%17 = call i32 @htons(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i32, i32* %3
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%24 = call i64 @bind(i32 %22, %struct.sockaddr* %23, i32 12)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %13
%27 = load i32, i32* @LOG_ERR
%28 = call i32 @syslog(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [26 x i8] c"Error binding socket name\00"
define i32 @create_socket(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @LOG_ERR
%10 = tail call i32 @syslog(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %1
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 %0)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%19 = call i64 @bind(i32 %6, %struct.sockaddr* %18, i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* @LOG_ERR
%23 = call i32 @syslog(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %11
ret i32 %6
}