#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 */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  void *sin_port;
  void *sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ local_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *htons(int);
int inet_pton(void *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  int sock_fd, err;
  struct sockaddr_in local_addr, server_addr;
  err = socket(AF_INET, SOCK_STREAM, 0);
  if (err < 0) {
    fprintf(stderr, "Eroare! Nu am putut deschide socket!\n");
    exit(-1);
  }
  memset(&local_addr, 0, sizeof(local_addr));
  local_addr.sin_family = AF_INET;
  local_addr.sin_port = htons(5005);
  err = inet_pton(AF_INET, "127.0.0.1", &local_addr.sin_addr.s_addr);
  if (err < 0) {
    fprintf(stderr, "Eroare! Nu am putut converti adresa!\n");
    exit(-1);
  }
  err = bind(sock_fd, (struct sockaddr *)&local_addr, sizeof(local_addr));
  if (err < 0) {
    fprintf(stderr, "Eroare la bind!\n");
    exit(-1);
  }
  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(5005);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c5 <main+0x55>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x138d,%edi
call   1030 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%rdi
lea    -0x28(%rbp),%rdx
add    $0x10,%rdx
lea    0xe1c(%rip),%rsi
call   1060 <inet_pton@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    123b <main+0xcb>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1278 <main+0x108>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    $0x138d,%edi
call   1030 <htons@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0x2e6c(%rip),%rbx
mov    (%rbx),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     120c <main+0x9c>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    (%rbx),%rax
mov    %rax,0x8(%rsp)
mov    $0x138d,%edi
call   1030 <htons@plt>
mov    %rax,(%rsp)
mov    (%rbx),%rdi
lea    0x10(%rsp),%rdx
lea    0xe5f(%rip),%rsi
call   1060 <inet_pton@plt>
test   %eax,%eax
js     121e <main+0xae>
mov    %rsp,%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
test   %eax,%eax
js     1230 <main+0xc0>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    (%rbx),%rax
mov    %rax,0x20(%rsp)
mov    $0x138d,%edi
call   1030 <htons@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
jmp    1240 <main+0xd0>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
jmp    1240 <main+0xd0>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Eroare! Nu am putut deschide socket!\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [38 x i8] c"Eroare! Nu am putut converti adresa!\0A\00"
@.str.3 = [17 x i8] c"Eroare la bind!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%6 = load i8*, i8** @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i8* %6, i32 %7, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 24)
%17 = load i8*, i8** @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i8* %17, i8** %18
%19 = call i8* @htons(i32 5005)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i8* %19, i8** %20
%21 = load i8*, i8** @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
%24 = call i32 @inet_pton(i8* %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %15
%32 = load i32, i32* %2
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 24)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %31
%42 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%43 = load i8*, i8** @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i8* %43, i8** %44
%45 = call i8* @htons(i32 5005)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i8* %45, i8** %46
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Eroare! Nu am putut deschide socket!\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [38 x i8] c"Eroare! Nu am putut converti adresa!\0A\00"
@.str.3 = [17 x i8] c"Eroare la bind!\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i8*, i8** @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i8* %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 24)
%15 = load i8*, i8** @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i8* %15, i8** %16
%17 = call i8* @htons(i32 5005)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i8* %17, i8** %18
%19 = load i8*, i8** @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2, i32 0
%21 = call i32 @inet_pton(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %13
%28 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%29 = call i32 @bind(i32 undef, %struct.sockaddr* %28, i32 24)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %27
%36 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 24)
%37 = load i8*, i8** @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i8* %37, i8** %38
%39 = call i8* @htons(i32 5005)
ret i32 0
}