#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 TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  scalar_t__ sin_family;
};
struct in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addrtype;
  int h_length;
  int /*<<< orphan*/ **h_addr_list;
};

/* Variables and functions */
scalar_t__ AF_INET;
int errno;
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ log_msg(char *);
int /*<<< orphan*/ printf(char *, char *, int, ...);
char *strerror(int);
int filladdr(char *host, struct sockaddr_in *addr) {
  struct hostent *h;
  h = gethostbyname(host);
  if (h != NULL) {
    if (AF_INET != h->h_addrtype) {
      do {
        log_msg("addrtype");
        printf("die %s:%d\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/"
               "master/mrr/mrr.c",
               505);
        exit(1);
      } while (0);
    }
    if (NULL == h->h_addr_list[0]) {
      do {
        log_msg("no address");
        printf("die %s:%d\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/"
               "master/mrr/mrr.c",
               508);
        exit(1);
      } while (0);
    }
    if (sizeof(struct in_addr) != h->h_length) {
      do {
        log_msg("h_length");
        printf("die %s:%d\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/"
               "master/mrr/mrr.c",
               511);
        exit(1);
      } while (0);
    }
    addr->sin_family = AF_INET;
    addr->sin_addr.s_addr = *((uint32_t *)h->h_addr_list[0]);
  } else {
    do {
      log_msg("gethostbyname");
      printf("%s(%d) die %s:%d\n", strerror(errno), errno,
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/master/mrr/"
             "mrr.c",
             518);
      exit(1);
    } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<filladdr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1281 <filladdr+0x131>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
je     11c4 <filladdr+0x74>
jmp    1194 <filladdr+0x44>
lea    0xe65(%rip),%rdi
call   1050 <log_msg@plt>
lea    0xf12(%rip),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x1f9,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    120c <filladdr+0xbc>
jmp    11dc <filladdr+0x8c>
lea    0xead(%rip),%rdi
call   1050 <log_msg@plt>
lea    0xeca(%rip),%rdi
lea    0xe13(%rip),%rsi
mov    $0x1fc,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
movslq 0x8(%rax),%rcx
mov    $0x4,%eax
cmp    %rcx,%rax
je     1257 <filladdr+0x107>
jmp    1227 <filladdr+0xd7>
lea    0xe6d(%rip),%rdi
call   1050 <log_msg@plt>
lea    0xe7f(%rip),%rdi
lea    0xdc8(%rip),%rsi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    12d1 <filladdr+0x181>
jmp    1286 <filladdr+0x136>
lea    0xe17(%rip),%rdi
call   1050 <log_msg@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
lea    0xdff(%rip),%rdi
lea    0xd4f(%rip),%rcx
mov    $0x206,%r8d
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filladdr>:
push   %rbx
mov    %rsi,%rbx
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     118f <filladdr+0x3f>
mov    0x2e83(%rip),%rcx
mov    (%rcx),%rcx
cmp    (%rax),%rcx
jne    11d3 <filladdr+0x83>
mov    0x10(%rax),%rdx
mov    (%rdx),%rdx
test   %rdx,%rdx
je     11f4 <filladdr+0xa4>
cmpl   $0x4,0x8(%rax)
jne    1215 <filladdr+0xc5>
mov    %rcx,0x8(%rbx)
mov    (%rdx),%eax
mov    %eax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret
lea    0xf0e(%rip),%rdi
call   1050 <log_msg@plt>
mov    0x2e36(%rip),%rbx
mov    (%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%edx
lea    0xf00(%rip),%rdi
lea    0xe50(%rip),%rcx
mov    %rax,%rsi
mov    $0x206,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe26(%rip),%rdi
call   1050 <log_msg@plt>
lea    0xed3(%rip),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x1f9,%edx
jmp    1234 <filladdr+0xe4>
lea    0xe95(%rip),%rdi
call   1050 <log_msg@plt>
lea    0xeb2(%rip),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x1fc,%edx
jmp    1234 <filladdr+0xe4>
lea    0xe7f(%rip),%rdi
call   1050 <log_msg@plt>
lea    0xe91(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64, i32, i32** }
@AF_INET = global i64 0
@.str = [9 x i8] c"addrtype\00"
@.str.1 = [11 x i8] c"die %s:%d\0A\00"
@.str.2 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/master/mrr/mrr.c\00"
@.str.3 = [11 x i8] c"no address\00"
@.str.4 = [9 x i8] c"h_length\00"
@.str.5 = [14 x i8] c"gethostbyname\00"
@.str.6 = [18 x i8] c"%s(%d) die %s:%d\0A\00"
@errno = global i32 0
define i32 @filladdr(i8* %0, %struct.sockaddr_in* %1) {
%3 = alloca i8*
%4 = alloca %struct.sockaddr_in*
%5 = alloca %struct.hostent*
store i8* %0, i8** %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
%6 = load i8*, i8** %3
%7 = call %struct.hostent* @gethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %5
%8 = load %struct.hostent*, %struct.hostent** %5
%9 = icmp ne %struct.hostent* %8, null
br i1 %9, label %10, label %60
10: ; preds = %2
%11 = load i64, i64* @AF_INET
%12 = load %struct.hostent*, %struct.hostent** %5
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp ne i64 %11, %14
br i1 %15, label %16, label %22
16: ; preds = %10
br label %17
17: ; preds = %16
%18 = call i32 @log_msg(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 505)
%20 = call i32 @exit(i32 1)
unreachable
21: ; No predecessors!
br label %22
22: ; preds = %21, %10
%23 = load %struct.hostent*, %struct.hostent** %5
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 2
%25 = load i32**, i32*** %24
%26 = getelementptr inbounds i32*, i32** %25, i64 0
%27 = load i32*, i32** %26
%28 = icmp eq i32* null, %27
br i1 %28, label %29, label %35
29: ; preds = %22
br label %30
30: ; preds = %29
%31 = call i32 @log_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 508)
%33 = call i32 @exit(i32 1)
unreachable
34: ; No predecessors!
br label %35
35: ; preds = %34, %22
%36 = load %struct.hostent*, %struct.hostent** %5
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = icmp ne i64 4, %39
br i1 %40, label %41, label %47
41: ; preds = %35
br label %42
42: ; preds = %41
%43 = call i32 @log_msg(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 511)
%45 = call i32 @exit(i32 1)
unreachable
46: ; No predecessors!
br label %47
47: ; preds = %46, %35
%48 = load i64, i64* @AF_INET
%49 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %49, i32 0, i32 1
store i64 %48, i64* %50
%51 = load %struct.hostent*, %struct.hostent** %5
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 2
%53 = load i32**, i32*** %52
%54 = getelementptr inbounds i32*, i32** %53, i64 0
%55 = load i32*, i32** %54
%56 = load i32, i32* %55
%57 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %57, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 0
store i32 %56, i32* %59
br label %69
60: ; preds = %2
br label %61
61: ; preds = %60
%62 = call i32 @log_msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = load i32, i32* @errno
%66 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %64, i32 %65, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 518)
%67 = call i32 @exit(i32 1)
unreachable
68: ; No predecessors!
br label %69
69: ; preds = %68, %47
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64, i32, i32** }
@AF_INET = global i64 0
@.str = [9 x i8] c"addrtype\00"
@.str.1 = [11 x i8] c"die %s:%d\0A\00"
@.str.2 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/master/mrr/mrr.c\00"
@.str.3 = [11 x i8] c"no address\00"
@.str.4 = [9 x i8] c"h_length\00"
@.str.5 = [14 x i8] c"gethostbyname\00"
@.str.6 = [18 x i8] c"%s(%d) die %s:%d\0A\00"
@errno = global i32 0
define i32 @filladdr(i8* %0, %struct.sockaddr_in* nocapture writeonly %1) {
%3 = tail call %struct.hostent* @gethostbyname(i8* %0)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %35, label %5
5: ; preds = %2
%6 = load i64, i64* @AF_INET
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%8 = load i64, i64* %7
%9 = icmp eq i64 %6, %8
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = tail call i32 @log_msg(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 505)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 2
%16 = load i32**, i32*** %15
%17 = load i32*, i32** %16
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = tail call i32 @log_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 508)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 4
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = tail call i32 @log_msg(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 511)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i64 %6, i64* %32
%33 = load i32, i32* %17
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %33, i32* %34
ret i32 0
35: ; preds = %2
%36 = tail call i32 @log_msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%37 = load i32, i32* @errno
%38 = tail call i8* @strerror(i32 %37)
%39 = load i32, i32* @errno
%40 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %38, i32 %39, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 518)
%41 = tail call i32 @exit(i32 1)
unreachable
}