#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 in_addr {
  scalar_t__ s_addr;
};

/* Variables and functions */
scalar_t__ INADDR_ANY;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(struct in_addr *);
scalar_t__ malloc(int);
int /*<<< orphan*/ ns_t_a;
int /*<<< orphan*/ ns_t_mx;
int query(char const *, int /*<<< orphan*/, struct in_addr *);
int /*<<< orphan*/ stderr;
struct in_addr *find_mail_exchanges(const char *domain_name) {
  struct in_addr *results =
      (struct in_addr *)malloc(32 * sizeof(struct in_addr));
  if (results == NULL) {
    fputs("malloc: out of memory\n", stderr);
    return NULL;
  }
  for (int i = 0; i < 32; ++i) {
    results[i].s_addr = INADDR_ANY;
  }
  int status;
  status = query(domain_name, ns_t_mx, results);
  if (status == 0) {
    status = query(domain_name, ns_t_a, results);
  }
  if (status == -1 || results[0].s_addr == INADDR_ANY) {
    fputs("find_mail_exchanges: none found\n", stderr);
    free(results);
    return NULL;
  }
  return results;
}


x86 assembly (clang, -O0):
<find_mail_exchanges>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <find_mail_exchanges+0x47>
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1040 <fputs@plt>
movq   $0x0,-0x8(%rbp)
jmp    124c <find_mail_exchanges+0x10c>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    11bc <find_mail_exchanges+0x7c>
mov    0x2e41(%rip),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <find_mail_exchanges+0x4e>
mov    -0x10(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1050 <query@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11f8 <find_mail_exchanges+0xb8>
mov    -0x10(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1050 <query@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
je     1219 <find_mail_exchanges+0xd9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%rax
jne    1244 <find_mail_exchanges+0x104>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    0xdee(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    124c <find_mail_exchanges+0x10c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_mail_exchanges>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x100,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1239 <find_mail_exchanges+0xf9>
mov    %rax,%rbx
mov    0x2e7b(%rip),%r15
mov    (%r15),%rax
mov    %rax,(%rbx)
mov    (%r15),%rax
mov    %rax,0x8(%rbx)
mov    %rax,0x10(%rbx)
mov    %rax,0x18(%rbx)
mov    %rax,0x20(%rbx)
mov    %rax,0x28(%rbx)
mov    %rax,0x30(%rbx)
mov    %rax,0x38(%rbx)
mov    %rax,0x40(%rbx)
mov    %rax,0x48(%rbx)
mov    %rax,0x50(%rbx)
mov    %rax,0x58(%rbx)
mov    %rax,0x60(%rbx)
mov    %rax,0x68(%rbx)
mov    %rax,0x70(%rbx)
mov    %rax,0x78(%rbx)
mov    %rax,0x80(%rbx)
mov    %rax,0x88(%rbx)
mov    %rax,0x90(%rbx)
mov    %rax,0x98(%rbx)
mov    %rax,0xa0(%rbx)
mov    %rax,0xa8(%rbx)
mov    %rax,0xb0(%rbx)
mov    %rax,0xb8(%rbx)
mov    %rax,0xc0(%rbx)
mov    %rax,0xc8(%rbx)
mov    %rax,0xd0(%rbx)
mov    %rax,0xd8(%rbx)
mov    %rax,0xe0(%rbx)
mov    %rax,0xe8(%rbx)
mov    %rax,0xf0(%rbx)
mov    %rax,0xf8(%rbx)
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <query@plt>
test   %eax,%eax
je     1250 <find_mail_exchanges+0x110>
cmp    $0xffffffff,%eax
jne    1269 <find_mail_exchanges+0x129>
jmp    1271 <find_mail_exchanges+0x131>
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    0xdb7(%rip),%rdi
call   1040 <fputs@plt>
jmp    128e <find_mail_exchanges+0x14e>
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <query@plt>
cmp    $0xffffffff,%eax
je     1271 <find_mail_exchanges+0x131>
mov    (%rbx),%rax
cmp    (%r15),%rax
jne    1290 <find_mail_exchanges+0x150>
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
lea    0xd96(%rip),%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i64 }
@.str = [23 x i8] c"malloc: out of memory\0A\00"
@stderr = global i32 0
@INADDR_ANY = global i64 0
@ns_t_mx = global i32 0
@ns_t_a = global i32 0
@.str.1 = [33 x i8] c"find_mail_exchanges: none found\0A\00"
define %struct.in_addr* @find_mail_exchanges(i8* %0) {
%2 = alloca %struct.in_addr*
%3 = alloca i8*
%4 = alloca %struct.in_addr*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i64 @malloc(i32 256)
%8 = inttoptr i64 %7 to %struct.in_addr*
store %struct.in_addr* %8, %struct.in_addr** %4
%9 = load %struct.in_addr*, %struct.in_addr** %4
%10 = icmp eq %struct.in_addr* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %12)
store %struct.in_addr* null, %struct.in_addr** %2
br label %57
14: ; preds = %1
store i32 0, i32* %5
br label %15
15: ; preds = %25, %14
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 32
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i64, i64* @INADDR_ANY
%20 = load %struct.in_addr*, %struct.in_addr** %4
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %20, i64 %22
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %23, i32 0, i32 0
store i64 %19, i64* %24
br label %25
25: ; preds = %18
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
%29 = load i8*, i8** %3
%30 = load i32, i32* @ns_t_mx
%31 = load %struct.in_addr*, %struct.in_addr** %4
%32 = call i32 @query(i8* %29, i32 %30, %struct.in_addr* %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i8*, i8** %3
%37 = load i32, i32* @ns_t_a
%38 = load %struct.in_addr*, %struct.in_addr** %4
%39 = call i32 @query(i8* %36, i32 %37, %struct.in_addr* %38)
store i32 %39, i32* %6
br label %40
40: ; preds = %35, %28
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, -1
br i1 %42, label %50, label %43
43: ; preds = %40
%44 = load %struct.in_addr*, %struct.in_addr** %4
%45 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %44, i64 0
%46 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = load i64, i64* @INADDR_ANY
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %55
50: ; preds = %43, %40
%51 = load i32, i32* @stderr
%52 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %51)
%53 = load %struct.in_addr*, %struct.in_addr** %4
%54 = call i32 @free(%struct.in_addr* %53)
store %struct.in_addr* null, %struct.in_addr** %2
br label %57
55: ; preds = %43
%56 = load %struct.in_addr*, %struct.in_addr** %4
store %struct.in_addr* %56, %struct.in_addr** %2
br label %57
57: ; preds = %55, %50, %11
%58 = load %struct.in_addr*, %struct.in_addr** %2
ret %struct.in_addr* %58
}

LLVM IR (-O2):
%struct.in_addr = type { i64 }
@.str = [23 x i8] c"malloc: out of memory\0A\00"
@stderr = global i32 0
@INADDR_ANY = global i64 0
@ns_t_mx = global i32 0
@ns_t_a = global i32 0
@.str.1 = [33 x i8] c"find_mail_exchanges: none found\0A\00"
define %struct.in_addr* @find_mail_exchanges(i8* %0) {
%2 = tail call i64 @malloc(i32 256)
%3 = inttoptr i64 %2 to %struct.in_addr*
%4 = icmp eq i64 %2, 0
br i1 %4, label %43, label %5
5: ; preds = %1
%6 = load i64, i64* @INADDR_ANY
%7 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
store i64 %6, i64* %7
%8 = load i64, i64* @INADDR_ANY
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 1, i32 0
store i64 %8, i64* %9
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 2, i32 0
store i64 %8, i64* %10
%11 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 3, i32 0
store i64 %8, i64* %11
%12 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 4, i32 0
store i64 %8, i64* %12
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 5, i32 0
store i64 %8, i64* %13
%14 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 6, i32 0
store i64 %8, i64* %14
%15 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 7, i32 0
store i64 %8, i64* %15
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 8, i32 0
store i64 %8, i64* %16
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 9, i32 0
store i64 %8, i64* %17
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 10, i32 0
store i64 %8, i64* %18
%19 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 11, i32 0
store i64 %8, i64* %19
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 12, i32 0
store i64 %8, i64* %20
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 13, i32 0
store i64 %8, i64* %21
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 14, i32 0
store i64 %8, i64* %22
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 15, i32 0
store i64 %8, i64* %23
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 16, i32 0
store i64 %8, i64* %24
%25 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 17, i32 0
store i64 %8, i64* %25
%26 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 18, i32 0
store i64 %8, i64* %26
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 19, i32 0
store i64 %8, i64* %27
%28 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 20, i32 0
store i64 %8, i64* %28
%29 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 21, i32 0
store i64 %8, i64* %29
%30 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 22, i32 0
store i64 %8, i64* %30
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 23, i32 0
store i64 %8, i64* %31
%32 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 24, i32 0
store i64 %8, i64* %32
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 25, i32 0
store i64 %8, i64* %33
%34 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 26, i32 0
store i64 %8, i64* %34
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 27, i32 0
store i64 %8, i64* %35
%36 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 28, i32 0
store i64 %8, i64* %36
%37 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 29, i32 0
store i64 %8, i64* %37
%38 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 30, i32 0
store i64 %8, i64* %38
%39 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 31, i32 0
store i64 %8, i64* %39
%40 = load i32, i32* @ns_t_mx
%41 = tail call i32 @query(i8* %0, i32 %40, %struct.in_addr* %3)
%42 = icmp eq i32 %41, 0
br i1 %42, label %46, label %49
43: ; preds = %1
%44 = load i32, i32* @stderr
%45 = tail call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %44)
br label %60
46: ; preds = %5
%47 = load i32, i32* @ns_t_a
%48 = tail call i32 @query(i8* %0, i32 %47, %struct.in_addr* %3)
br label %49
49: ; preds = %46, %5
%50 = phi i32 [ %48, %46 ], [ %41, %5 ]
%51 = icmp eq i32 %50, -1
br i1 %51, label %56, label %52
52: ; preds = %49
%53 = load i64, i64* %7
%54 = load i64, i64* @INADDR_ANY
%55 = icmp eq i64 %53, %54
br i1 %55, label %56, label %60
56: ; preds = %52, %49
%57 = load i32, i32* @stderr
%58 = tail call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = tail call i32 @free(%struct.in_addr* %3)
br label %60
60: ; preds = %56, %52, %43
%61 = phi %struct.in_addr* [ null, %43 ], [ null, %56 ], [ %3, %52 ]
ret %struct.in_addr* %61
}