#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ *ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int traduce_a_direccion(const char *maquina, const char *puerto, int tipo,
                        struct addrinfo *info) {
  struct addrinfo hints;
  struct addrinfo *result;
  int error = 0;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  if (0 == tipo)
    hints.ai_socktype = SOCK_DGRAM;
  else
    hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = 0;
  if (2 == tipo)
    hints.ai_flags |= AI_PASSIVE;
  error = getaddrinfo(maquina, puerto, &hints, &result);
  if (error != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
  } else {
    if (result == NULL) {
      fprintf(stderr, "No se han encontrado direcciones.\n");
      error = 1;
    } else {
      info->ai_family = result->ai_family;
      info->ai_socktype = result->ai_socktype;
      info->ai_protocol = result->ai_protocol;
      *info->ai_addr = *result->ai_addr;
      info->ai_addrlen = result->ai_addrlen;
    }
    freeaddrinfo(result);
  }
  return !error;
}


x86 assembly (clang, -O0):
<traduce_a_direccion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x54(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11a6 <traduce_a_direccion+0x56>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    11b2 <traduce_a_direccion+0x62>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x2,%eax
cmp    -0x14(%rbp),%eax
jne    11d7 <traduce_a_direccion+0x87>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1226 <traduce_a_direccion+0xd6>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12a9 <traduce_a_direccion+0x159>
cmpq   $0x0,-0x50(%rbp)
jne    1254 <traduce_a_direccion+0x104>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x54(%rbp)
jmp    12a0 <traduce_a_direccion+0x150>
mov    -0x50(%rbp),%rax
mov    0x1c(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    -0x50(%rbp),%rax
mov    0x18(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
cmpl   $0x0,-0x54(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traduce_a_direccion>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
test   %ebp,%ebp
je     11b1 <traduce_a_direccion+0x61>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
cmp    $0x2,%ebp
jne    11c7 <traduce_a_direccion+0x77>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
or     %eax,0x30(%rsp)
jmp    11c7 <traduce_a_direccion+0x77>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <getaddrinfo@plt>
test   %eax,%eax
je     120a <traduce_a_direccion+0xba>
mov    0x2de1(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe09(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
jmp    1265 <traduce_a_direccion+0x115>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     123f <traduce_a_direccion+0xef>
mov    0x1c(%rdi),%eax
mov    %eax,0x1c(%r14)
mov    0x18(%rdi),%eax
mov    %eax,0x18(%r14)
mov    0x10(%rdi),%rax
mov    %rax,0x10(%r14)
mov    0x8(%rdi),%rax
mov    (%rax),%eax
mov    0x8(%r14),%rcx
mov    %eax,(%rcx)
mov    (%rdi),%eax
mov    %eax,(%r14)
xor    %ebx,%ebx
jmp    1260 <traduce_a_direccion+0x110>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    0x8(%rsp),%rdi
call   1070 <freeaddrinfo@plt>
xor    %eax,%eax
test   %ebx,%ebx
sete   %al
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32*, i64, i32, i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.1 = [35 x i8] c"No se han encontrado direcciones.\0A\00"
define i32 @traduce_a_direccion(i8* %0, i8* %1, i32 %2, %struct.addrinfo* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store %struct.addrinfo* %3, %struct.addrinfo** %8
store i32 0, i32* %11
%12 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 40)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i32 %13, i32* %14
%15 = load i32, i32* %7
%16 = icmp eq i32 0, %15
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load i32, i32* @SOCK_DGRAM
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 3
store i32 %18, i32* %19
br label %23
20: ; preds = %4
%21 = load i32, i32* @SOCK_STREAM
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 3
store i32 %21, i32* %22
br label %23
23: ; preds = %20, %17
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 2
store i64 0, i64* %24
%25 = load i32, i32* %7
%26 = icmp eq i32 2, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @AI_PASSIVE
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 5
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
br label %32
32: ; preds = %27, %23
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = call i32 @getaddrinfo(i8* %33, i8* %34, %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %32
%39 = load i32, i32* @stderr
%40 = load i32, i32* %11
%41 = call i8* @gai_strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %41)
br label %80
43: ; preds = %32
%44 = load %struct.addrinfo*, %struct.addrinfo** %10
%45 = icmp eq %struct.addrinfo* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %11
br label %77
49: ; preds = %43
%50 = load %struct.addrinfo*, %struct.addrinfo** %10
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 4
%52 = load i32, i32* %51
%53 = load %struct.addrinfo*, %struct.addrinfo** %8
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 4
store i32 %52, i32* %54
%55 = load %struct.addrinfo*, %struct.addrinfo** %10
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 3
%57 = load i32, i32* %56
%58 = load %struct.addrinfo*, %struct.addrinfo** %8
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 3
store i32 %57, i32* %59
%60 = load %struct.addrinfo*, %struct.addrinfo** %10
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i32 0, i32 2
%62 = load i64, i64* %61
%63 = load %struct.addrinfo*, %struct.addrinfo** %8
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 2
store i64 %62, i64* %64
%65 = load %struct.addrinfo*, %struct.addrinfo** %10
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 1
%67 = load i32*, i32** %66
%68 = load i32, i32* %67
%69 = load %struct.addrinfo*, %struct.addrinfo** %8
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
%71 = load i32*, i32** %70
store i32 %68, i32* %71
%72 = load %struct.addrinfo*, %struct.addrinfo** %10
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = load %struct.addrinfo*, %struct.addrinfo** %8
%76 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %75, i32 0, i32 0
store i32 %74, i32* %76
br label %77
77: ; preds = %49, %46
%78 = load %struct.addrinfo*, %struct.addrinfo** %10
%79 = call i32 @freeaddrinfo(%struct.addrinfo* %78)
br label %80
80: ; preds = %77, %38
%81 = load i32, i32* %11
%82 = icmp ne i32 %81, 0
%83 = xor i1 %82, true
%84 = zext i1 %83 to i32
ret i32 %84
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32*, i64, i32, i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.1 = [35 x i8] c"No se han encontrado direcciones.\0A\00"
define i32 @traduce_a_direccion(i8* %0, i8* %1, i32 %2, %struct.addrinfo* nocapture %3) {
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = bitcast %struct.addrinfo* %5 to i8*
%8 = bitcast %struct.addrinfo** %6 to i8*
%9 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 40)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %10, i32* %11
%12 = icmp eq i32 %2, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i32, i32* @SOCK_DGRAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 2
store i64 0, i64* %16
br label %27
17: ; preds = %4
%18 = load i32, i32* @SOCK_STREAM
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 2
store i64 0, i64* %20
%21 = icmp eq i32 %2, 2
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @AI_PASSIVE
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 5
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
br label %27
27: ; preds = %13, %22, %17
%28 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %5, %struct.addrinfo** %6)
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i8* @gai_strerror(i32 %28)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %63
34: ; preds = %27
%35 = load %struct.addrinfo*, %struct.addrinfo** %6
%36 = icmp eq %struct.addrinfo* %35, null
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%40 = load %struct.addrinfo*, %struct.addrinfo** %6
br label %59
41: ; preds = %34
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 4
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %43, i32* %44
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 3
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 2
%49 = load i64, i64* %48
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 %49, i64* %50
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%52 = load i32*, i32** %51
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
%55 = load i32*, i32** %54
store i32 %53, i32* %55
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %57, i32* %58
br label %59
59: ; preds = %41, %37
%60 = phi %struct.addrinfo* [ %40, %37 ], [ %35, %41 ]
%61 = phi i32 [ 1, %37 ], [ 0, %41 ]
%62 = call i32 @freeaddrinfo(%struct.addrinfo* %60)
br label %63
63: ; preds = %59, %30
%64 = phi i32 [ 1, %30 ], [ %61, %59 ]
%65 = icmp eq i32 %64, 0
%66 = zext i1 %65 to i32
ret i32 %66
}