#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 */
typedef int /*<<< orphan*/ uint32_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  TYPE_1__ *ai_addr;
  int /*<<< orphan*/ *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  scalar_t__ ai_protocol;
  scalar_t__ ai_flags;
  int /*<<< orphan*/ ai_socktype;
  scalar_t__ ai_family;
};
typedef int /*<<< orphan*/ ip;
struct TYPE_2__ {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ printf(char *, char *, char *, int);
uint32_t socketHostLookup(char *host, const char **error) {
  struct addrinfo hints;
  struct addrinfo *addr;
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  int result = getaddrinfo(host, NULL, &hints, &addr);
  if (result == 0) {
    if (!(addr->ai_addr->sa_family == AF_INET)) {
      printf("Assertion '%s' failed in %s:%u\n",
             "addr->ai_addr->sa_family == AF_INET",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/lm/yet-another-smalltalk-vm/refs/heads/"
             "master/vm/Socket.c",
             79);
      abort();
    };
    uint32_t ip;
    memcpy(&ip, &((struct sockaddr_in *)addr->ai_addr)->sin_addr, sizeof(ip));
    *error = NULL;
    freeaddrinfo(addr);
    return ip;
  } else {
    *error = gai_strerror(result);
    return 0;
  }
}


x86 assembly (clang, -O0):
<socketHostLookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    1248 <socketHostLookup+0xe8>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
je     1214 <socketHostLookup+0xb4>
lea    0xe0b(%rip),%rdi
lea    0xe24(%rip),%rsi
lea    0xe41(%rip),%rdx
mov    $0x4f,%ecx
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%rsi
lea    -0x60(%rbp),%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x58(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1261 <socketHostLookup+0x101>
mov    -0x5c(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketHostLookup>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    0x2e75(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x40(%rsp)
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x30(%rsp)
xor    %ebx,%ebx
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
xor    %esi,%esi
call   1070 <getaddrinfo@plt>
test   %eax,%eax
je     11c1 <socketHostLookup+0x61>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
mov    %rax,(%r14)
jmp    11f5 <socketHostLookup+0x95>
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
mov    (%rsi),%rax
cmp    (%r15),%rax
jne    1201 <socketHostLookup+0xa1>
lea    0x4(%rsp),%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
movq   $0x0,(%r14)
mov    0x8(%rsp),%rdi
call   1080 <freeaddrinfo@plt>
mov    0x4(%rsp),%ebx
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf8(%rip),%rdi
lea    0xe11(%rip),%rsi
lea    0xe2e(%rip),%rdx
mov    $0x4f,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.addrinfo = type { %struct.TYPE_2__*, i32*, i32*, i64, i64, i32, i64 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i64 0
@SOCK_STREAM = global i32 0
@.str = [32 x i8] c"Assertion '%s' failed in %s:%u\0A\00"
@.str.1 = [36 x i8] c"addr->ai_addr->sa_family == AF_INET\00"
@.str.2 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lm/yet-another-smalltalk-vm/refs/heads/master/vm/Socket.c\00"
define i32 @socketHostLookup(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%10 = load i64, i64* @AF_INET
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i64 %10, i64* %11
%12 = load i32, i32* @SOCK_STREAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i64 0, i64* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i64 0, i64* %15
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i32* null, i32** %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store %struct.TYPE_2__* null, %struct.TYPE_2__** %17
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32* null, i32** %18
%19 = load i8*, i8** %4
%20 = call i32 @getaddrinfo(i8* %19, i32* null, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %45
23: ; preds = %2
%24 = load %struct.addrinfo*, %struct.addrinfo** %7
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i32 0, i32 0
%26 = load %struct.TYPE_2__*, %struct.TYPE_2__** %25
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = load i64, i64* @AF_INET
%30 = icmp eq i64 %28, %29
br i1 %30, label %34, label %31
31: ; preds = %23
%32 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.2, i64 0, i64 0), i32 79)
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %23
%35 = load %struct.addrinfo*, %struct.addrinfo** %7
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 0
%37 = load %struct.TYPE_2__*, %struct.TYPE_2__** %36
%38 = bitcast %struct.TYPE_2__* %37 to %struct.sockaddr_in*
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %38, i32 0, i32 0
%40 = call i32 @memcpy(i32* %9, i32* %39, i32 4)
%41 = load i8**, i8*** %5
store i8* null, i8** %41
%42 = load %struct.addrinfo*, %struct.addrinfo** %7
%43 = call i32 @freeaddrinfo(%struct.addrinfo* %42)
%44 = load i32, i32* %9
store i32 %44, i32* %3
br label %49
45: ; preds = %2
%46 = load i32, i32* %8
%47 = call i8* @gai_strerror(i32 %46)
%48 = load i8**, i8*** %5
store i8* %47, i8** %48
store i32 0, i32* %3
br label %49
49: ; preds = %45, %34
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.TYPE_2__*, i32*, i32*, i64, i64, i32, i64 }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
@SOCK_STREAM = global i32 0
@.str = [32 x i8] c"Assertion '%s' failed in %s:%u\0A\00"
@.str.1 = [36 x i8] c"addr->ai_addr->sa_family == AF_INET\00"
@.str.2 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lm/yet-another-smalltalk-vm/refs/heads/master/vm/Socket.c\00"
define i32 @socketHostLookup(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca i32
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = load i64, i64* @AF_INET
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i64 %8, i64* %9
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %10, i32* %11
%12 = bitcast %struct.addrinfo* %3 to i8*
%13 = call i32 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %2
%16 = load %struct.addrinfo*, %struct.addrinfo** %4
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i64 0, i32 0
%18 = load %struct.TYPE_2__*, %struct.TYPE_2__** %17
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i64 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* @AF_INET
%22 = icmp eq i64 %20, %21
br i1 %22, label %26, label %23
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.2, i64 0, i64 0), i32 79)
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %15
%27 = bitcast i32* %5 to i8*
%28 = bitcast %struct.TYPE_2__* %18 to i32*
%29 = call i32 @memcpy(i32* %5, i32* %28, i32 4)
store i8* null, i8** %1
%30 = load %struct.addrinfo*, %struct.addrinfo** %4
%31 = call i32 @freeaddrinfo(%struct.addrinfo* %30)
%32 = load i32, i32* %5
br label %35
33: ; preds = %2
%34 = call i8* @gai_strerror(i32 %13)
store i8* %34, i8** %1
br label %35
35: ; preds = %33, %26
%36 = phi i32 [ %32, %26 ], [ 0, %33 ]
ret i32 %36
}