#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct protoent {
  int /*<<< orphan*/ p_proto;
};
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, void *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct protoent *getprotobyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct sockaddr_in address;
  struct protoent *pr;
  int sock;
  if (argc != 2) {
    fprintf(stderr, "Uso: %s <protocollo>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((pr = getprotobyname(argv[1])) == NULL) {
    fprintf(stderr, "Err. getprotobyname()\n");
    exit(EXIT_FAILURE);
  }
  if ((sock = socket(AF_INET, SOCK_STREAM, pr->p_proto)) < 0) {
    fprintf(stderr, "Err. socket() - %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = INADDR_ANY;
  address.sin_port = htons(7000);
  if (bind(sock, (void *)&address, sizeof(address)) < 0) {
    fprintf(stderr, "Err. bind() - %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  sleep(30);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cc <main+0x4c>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <getprotobyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120c <main+0x8c>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1271 <main+0xf1>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1b58,%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    12ed <main+0x16d>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd69(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x1e,%edi
call   1090 <sleep@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1219 <main+0x99>
mov    0x8(%rsi),%rdi
call   1050 <getprotobyname@plt>
test   %rax,%rax
je     122e <main+0xae>
mov    0x2e3f(%rip),%r14
mov    (%r14),%edi
mov    0x2e15(%rip),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1247 <main+0xc7>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x1b58,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1060 <bind@plt>
test   %rax,%rax
js     1267 <main+0xe7>
mov    $0x1e,%edi
call   1090 <sleep@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdd4(%rip),%rsi
jmp    128a <main+0x10a>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1291 <main+0x111>
mov    0x2d82(%rip),%rax
mov    (%rax),%ebx
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdc8(%rip),%rsi
jmp    1285 <main+0x105>
mov    0x2d62(%rip),%rax
mov    (%rax),%ebx
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdbc(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.protoent = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Uso: %s <protocollo>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"Err. getprotobyname()\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [20 x i8] c"Err. socket() - %s\0A\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.3 = [18 x i8] c"Err. bind() - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.protoent*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call %struct.protoent* @getprotobyname(i8* %22)
store %struct.protoent* %23, %struct.protoent** %7
%24 = icmp eq %struct.protoent* %23, null
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = load i32, i32* @AF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = load %struct.protoent*, %struct.protoent** %7
%34 = getelementptr inbounds %struct.protoent, %struct.protoent* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @socket(i32 %31, i32 %32, i32 %35)
store i32 %36, i32* %8
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %30
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %46, i32* %47
%48 = load i32, i32* @INADDR_ANY
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
store i32 %48, i32* %50
%51 = call i32 @htons(i32 7000)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %51, i32* %52
%53 = load i32, i32* %8
%54 = bitcast %struct.sockaddr_in* %6 to i8*
%55 = call i64 @bind(i32 %53, i8* %54, i32 12)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %45
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %60)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %45
%65 = call i32 @sleep(i32 30)
%66 = load i32, i32* @EXIT_SUCCESS
ret i32 %66
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.protoent = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Uso: %s <protocollo>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"Err. getprotobyname()\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [20 x i8] c"Err. socket() - %s\0A\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.3 = [18 x i8] c"Err. bind() - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.protoent* @getprotobyname(i8* %14)
%16 = icmp eq %struct.protoent* %15, null
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = getelementptr inbounds %struct.protoent, %struct.protoent* %15, i64 0, i32 0
%26 = load i32, i32* %25
%27 = tail call i32 @socket(i32 %23, i32 %24, i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %22
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %37, i32* %38
%39 = load i32, i32* @INADDR_ANY
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %39, i32* %40
%41 = tail call i32 @htons(i32 7000)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %41, i32* %42
%43 = call i64 @bind(i32 %27, i8* %4, i32 12)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %36
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %36
%53 = call i32 @sleep(i32 30)
%54 = load i32, i32* @EXIT_SUCCESS
ret i32 %54
}