#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 {
  int p_proto;
};

/* Variables and functions */
int AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int SOCK_DGRAM;
struct protoent *getprotobyname(char *);
int /*<<< orphan*/ perror(char *);
int socket(int, int, int);
int main(int argc, char *argv[]) {
  int dominio = AF_INET;
  int tipo = SOCK_DGRAM;
  int protocollo = 0;
  int skt;
  struct protoent *proto_info;
  proto_info = getprotobyname("udp");
  if (proto_info == NULL) {
    perror("getprotobyname");
    return (EXIT_FAILURE);
  }
  protocollo = proto_info->p_proto;
  skt = socket(dominio, tipo, protocollo);
  if (skt < 0) {
    perror("socket");
    return (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    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe94(%rip),%rdi
call   1030 <getprotobyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <main+0x6d>
lea    0xe7d(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ea <main+0xba>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11de <main+0xae>
lea    0xe4b(%rip),%rdi
call   1040 <perror@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ea <main+0xba>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%ebx
mov    0x2e9d(%rip),%rax
mov    (%rax),%ebp
lea    0xeb4(%rip),%rdi
call   1030 <getprotobyname@plt>
test   %rax,%rax
je     1175 <main+0x45>
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <socket@plt>
test   %eax,%eax
js     117e <main+0x4e>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe88(%rip),%rdi
jmp    1185 <main+0x55>
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3f(%rip),%rax
jmp    116c <main+0x3c>

LLVM IR (-O0):
%struct.protoent = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [4 x i8] c"udp\00"
@.str.1 = [15 x i8] c"getprotobyname\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@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 = call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store %struct.protoent* %13, %struct.protoent** %10
%14 = load %struct.protoent*, %struct.protoent** %10
%15 = icmp eq %struct.protoent* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %34
19: ; preds = %2
%20 = load %struct.protoent*, %struct.protoent** %10
%21 = getelementptr inbounds %struct.protoent, %struct.protoent* %20, i32 0, i32 0
%22 = load i32, i32* %21
store i32 %22, i32* %8
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call i32 @socket(i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %34
32: ; preds = %19
%33 = load i32, i32* @EXIT_SUCCESS
store i32 %33, i32* %3
br label %34
34: ; preds = %32, %29, %16
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.protoent = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [4 x i8] c"udp\00"
@.str.1 = [15 x i8] c"getprotobyname\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq %struct.protoent* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.protoent, %struct.protoent* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @socket(i32 %3, i32 %4, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7, %2
%13 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %7 ]
%14 = tail call i32 @perror(i8* %13)
br label %15
15: ; preds = %12, %7
%16 = phi i32* [ @EXIT_SUCCESS, %7 ], [ @EXIT_FAILURE, %12 ]
%17 = load i32, i32* %16
ret i32 %17
}