#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 protoent {
  char *p_name;
  char **p_aliases;
  int p_proto;
};

/* Variables and functions */
int AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int SOCK_DGRAM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct protoent *getprotobyname(char *);
int /*<<< orphan*/ printf(char *, char *, char *, char *, int);
int socket(int, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int dominio = AF_INET;
  int tipo = SOCK_DGRAM;
  int protocollo = 0;
  int skt;
  struct protoent *proto_info;
  if (argc != 2) {
    fprintf(stderr, "Uso: %s <protocollo>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((proto_info = getprotobyname(argv[1])) == NULL) {
    fprintf(stderr, "Err. getprotobyname()\n");
    exit(EXIT_FAILURE);
  }
  printf("Informazioni su \'%s\'\n"
         "- nome: %s\n- alias: %s\n- numero protocollo: %d\n",
         argv[1], proto_info->p_name, *proto_info->p_aliases,
         proto_info->p_proto);
  protocollo = proto_info->p_proto;
  if ((skt = socket(dominio, tipo, protocollo)) < 0) {
    fprintf(stderr, "Err. socket() - %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cb <main+0x6b>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <getprotobyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120b <main+0xab>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%r8d
lea    0xdf9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1080 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1299 <main+0x139>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11d8 <main+0x78>
mov    0x2e72(%rip),%rax
mov    (%rax),%r14d
mov    0x2e60(%rip),%rax
mov    (%rax),%r15d
mov    0x8(%rbx),%rdi
call   1050 <getprotobyname@plt>
test   %rax,%rax
je     11ed <main+0x8d>
mov    %rax,%rbp
mov    0x8(%rbx),%rsi
mov    (%rax),%rdx
mov    0x8(%rax),%rax
mov    (%rax),%rcx
mov    0x10(%rbp),%r8d
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rbp),%edx
mov    %r14d,%edi
mov    %r15d,%esi
call   1080 <socket@plt>
test   %eax,%eax
js     1206 <main+0xa6>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe15(%rip),%rsi
jmp    1229 <main+0xc9>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1230 <main+0xd0>
mov    0x2dc3(%rip),%rax
mov    (%rax),%ebx
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe4e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.protoent = type { i8*, i8**, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@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"
@.str.2 = [69 x i8] c"Informazioni su '%s'\0A- nome: %s\0A- alias: %s\0A- numero protocollo: %d\0A\00"
@.str.3 = [20 x i8] c"Err. socket() - %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.protoent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_INET
store i32 %11, i32* %6
%12 = load i32, i32* @SOCK_DGRAM
store i32 %12, i32* %7
store i32 0, i32* %8
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call %struct.protoent* @getprotobyname(i8* %26)
store %struct.protoent* %27, %struct.protoent** %10
%28 = icmp eq %struct.protoent* %27, null
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %23
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load %struct.protoent*, %struct.protoent** %10
%39 = getelementptr inbounds %struct.protoent, %struct.protoent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = load %struct.protoent*, %struct.protoent** %10
%42 = getelementptr inbounds %struct.protoent, %struct.protoent* %41, i32 0, i32 1
%43 = load i8**, i8*** %42
%44 = load i8*, i8** %43
%45 = load %struct.protoent*, %struct.protoent** %10
%46 = getelementptr inbounds %struct.protoent, %struct.protoent* %45, i32 0, i32 2
%47 = load i32, i32* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %40, i8* %44, i32 %47)
%49 = load %struct.protoent*, %struct.protoent** %10
%50 = getelementptr inbounds %struct.protoent, %struct.protoent* %49, i32 0, i32 2
%51 = load i32, i32* %50
store i32 %51, i32* %8
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = call i32 @socket(i32 %52, i32 %53, i32 %54)
store i32 %55, i32* %9
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %34
%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 ([20 x i8], [20 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 = %34
%65 = load i32, i32* @EXIT_SUCCESS
ret i32 %65
}

LLVM IR (-O2):
%struct.protoent = type { i8*, i8**, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@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"
@.str.2 = [69 x i8] c"Informazioni su '%s'\0A- nome: %s\0A- alias: %s\0A- numero protocollo: %d\0A\00"
@.str.3 = [20 x i8] c"Err. socket() - %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%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 i8*, i8** %13
%24 = getelementptr inbounds %struct.protoent, %struct.protoent* %15, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.protoent, %struct.protoent* %15, i64 0, i32 1
%27 = load i8**, i8*** %26
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.protoent, %struct.protoent* %15, i64 0, i32 2
%30 = load i32, i32* %29
%31 = tail call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %25, i8* %28, i32 %30)
%32 = load i32, i32* %29
%33 = tail call i32 @socket(i32 %3, i32 %4, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %22
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = tail call i8* @strerror(i32 %37)
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %22
%43 = load i32, i32* @EXIT_SUCCESS
ret i32 %43
}