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

/* Variables and functions */
int /*<<< orphan*/ cctools_debug(long long, char *, char *, ...);
int /*<<< orphan*/ cctools_fatal(char *);
struct datagram *datagram_create(int /*<<< orphan*/);
int /*<<< orphan*/ datagram_delete(struct datagram *);
int /*<<< orphan*/ datagram_send(struct datagram *, char const *,
                                 int /*<<< orphan*/, char *, int);
scalar_t__ domain_name_cache_lookup(char *, char *);
char *parse_hostlist(char const *, char *, int *);
int /*<<< orphan*/ strlen(char const *);
int catalog_query_send_update(const char *hosts, const char *text) {
  int port;
  int sent = 0;
  const char *next_host = hosts;
  char address[48];
  char host[256];
  struct datagram *d = datagram_create(0);
  if (!d) {
    cctools_fatal("could not create datagram port!");
  }
  do {
    next_host = parse_hostlist(next_host, host, &port);
    if (domain_name_cache_lookup(host, address)) {
      cctools_debug((1LL << 3), "sending update to %s(%s):%d", host, address,
                    port);
      datagram_send(d, text, strlen(text), address, port);
      sent++;
    } else {
      cctools_debug((1LL << 3), "unable to lookup address of host: %s", host);
    }
  } while (next_host);
  datagram_delete(d);
  return sent;
}


x86 assembly (clang, -O0):
<catalog_query_send_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   1030 <datagram_create@plt>
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
jne    11ca <catalog_query_send_update+0x4a>
lea    0xe3b(%rip),%rdi
call   1060 <cctools_fatal@plt>
jmp    11cf <catalog_query_send_update+0x4f>
mov    -0x20(%rbp),%rdi
lea    -0x150(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1080 <parse_hostlist@plt>
mov    %rax,-0x20(%rbp)
lea    -0x150(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <domain_name_cache_lookup@plt>
cmp    $0x0,%rax
je     1270 <catalog_query_send_update+0xf0>
lea    -0x150(%rbp),%rdx
lea    -0x50(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    $0x8,%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1070 <cctools_debug@plt>
mov    -0x158(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x168(%rbp),%rdi
mov    -0x160(%rbp),%rsi
mov    %eax,%edx
lea    -0x50(%rbp),%rcx
mov    -0x14(%rbp),%r8d
call   10a0 <datagram_send@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    128a <catalog_query_send_update+0x10a>
lea    -0x150(%rbp),%rdx
mov    $0x8,%edi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1070 <cctools_debug@plt>
jmp    128f <catalog_query_send_update+0x10f>
cmpq   $0x0,-0x20(%rbp)
jne    11cf <catalog_query_send_update+0x4f>
mov    -0x158(%rbp),%rdi
call   1090 <datagram_delete@plt>
mov    -0x18(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catalog_query_send_update>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %edi,%edi
call   1030 <datagram_create@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11b2 <catalog_query_send_update+0x32>
lea    0xe53(%rip),%rdi
call   1060 <cctools_fatal@plt>
lea    0x40(%rsp),%r12
lea    0x10(%rsp),%r13
xor    %ebp,%ebp
jmp    11db <catalog_query_send_update+0x5b>
mov    $0x8,%edi
lea    0xe70(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <cctools_debug@plt>
test   %rbx,%rbx
je     1241 <catalog_query_send_update+0xc1>
mov    %rbx,%rdi
mov    %r12,%rsi
lea    0xc(%rsp),%rdx
call   1080 <parse_hostlist@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <domain_name_cache_lookup@plt>
test   %rax,%rax
je     11c0 <catalog_query_send_update+0x40>
mov    0xc(%rsp),%r8d
mov    $0x8,%edi
lea    0xe11(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <cctools_debug@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    0xc(%rsp),%r8d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %r13,%rcx
call   10a0 <datagram_send@plt>
add    $0x1,%ebp
test   %rbx,%rbx
jne    11db <catalog_query_send_update+0x5b>
mov    %r14,%rdi
call   1090 <datagram_delete@plt>
mov    %ebp,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.datagram = type { i32 }
@.str = [32 x i8] c"could not create datagram port!\00"
@.str.1 = [28 x i8] c"sending update to %s(%s):%d\00"
@.str.2 = [37 x i8] c"unable to lookup address of host: %s\00"
define i32 @catalog_query_send_update(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [48 x i8]
%9 = alloca [256 x i8]
%10 = alloca %struct.datagram*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%11 = load i8*, i8** %3
store i8* %11, i8** %7
%12 = call %struct.datagram* @datagram_create(i32 0)
store %struct.datagram* %12, %struct.datagram** %10
%13 = load %struct.datagram*, %struct.datagram** %10
%14 = icmp ne %struct.datagram* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 @cctools_fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
br label %18
18: ; preds = %44, %17
%19 = load i8*, i8** %7
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%21 = call i8* @parse_hostlist(i8* %19, i8* %20, i32* %5)
store i8* %21, i8** %7
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%23 = getelementptr inbounds [48 x i8], [48 x i8]* %8, i64 0, i64 0
%24 = call i64 @domain_name_cache_lookup(i8* %22, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %18
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = getelementptr inbounds [48 x i8], [48 x i8]* %8, i64 0, i64 0
%29 = load i32, i32* %5
%30 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %28, i32 %29)
%31 = load %struct.datagram*, %struct.datagram** %10
%32 = load i8*, i8** %4
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
%35 = getelementptr inbounds [48 x i8], [48 x i8]* %8, i64 0, i64 0
%36 = load i32, i32* %5
%37 = call i32 @datagram_send(%struct.datagram* %31, i8* %32, i32 %34, i8* %35, i32 %36)
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %43
40: ; preds = %18
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%42 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %26
br label %44
44: ; preds = %43
%45 = load i8*, i8** %7
%46 = icmp ne i8* %45, null
br i1 %46, label %18, label %47
47: ; preds = %44
%48 = load %struct.datagram*, %struct.datagram** %10
%49 = call i32 @datagram_delete(%struct.datagram* %48)
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
%struct.datagram = type { i32 }
@.str = [32 x i8] c"could not create datagram port!\00"
@.str.1 = [28 x i8] c"sending update to %s(%s):%d\00"
@.str.2 = [37 x i8] c"unable to lookup address of host: %s\00"
define i32 @catalog_query_send_update(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [48 x i8]
%5 = alloca [256 x i8]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [48 x i8], [48 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = tail call %struct.datagram* @datagram_create(i32 0)
%10 = icmp eq %struct.datagram* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @cctools_fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
br label %14
14: ; preds = %13, %29
%15 = phi i8* [ %17, %29 ], [ %0, %13 ]
%16 = phi i32 [ %30, %29 ], [ 0, %13 ]
%17 = call i8* @parse_hostlist(i8* %15, i8* %8, i32* %3)
%18 = call i64 @domain_name_cache_lookup(i8* %8, i8* %7)
%19 = icmp eq i64 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %14
%21 = load i32, i32* %3
%22 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %7, i32 %21)
%23 = call i32 @strlen(i8* %1)
%24 = load i32, i32* %3
%25 = call i32 @datagram_send(%struct.datagram* %9, i8* %1, i32 %23, i8* %7, i32 %24)
%26 = add nsw i32 %16, 1
br label %29
27: ; preds = %14
%28 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %29
29: ; preds = %20, %27
%30 = phi i32 [ %26, %20 ], [ %16, %27 ]
%31 = icmp eq i8* %17, null
br i1 %31, label %32, label %14
32: ; preds = %29
%33 = call i32 @datagram_delete(%struct.datagram* %9)
ret i32 %30
}