#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 */
typedef int u_int16_t;
typedef int /*<<< orphan*/ u_char;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
typedef int /*<<< orphan*/ ns_rr;
typedef int /*<<< orphan*/ ns_msg;
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ add(struct in_addr *, struct in_addr);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int);
int /*<<< orphan*/ memset(struct in_addr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *ns_rr_rdata(int /*<<< orphan*/);
int ns_rr_rdlen(int /*<<< orphan*/);
scalar_t__ ns_rr_type(int /*<<< orphan*/);
scalar_t__ ns_t_a;
int /*<<< orphan*/ stderr;
int process_a_record(ns_msg *handle, ns_rr *record, struct in_addr *results) {
  if (ns_rr_type(*record) != ns_t_a) {
    fputs("unexpected resource record type\n", stderr);
    return -1;
  }
  const u_char *data = ns_rr_rdata(*record);
  u_int16_t data_len = ns_rr_rdlen(*record);
  if (data_len != 4) {
    fputs("malformed resource record\n", stderr);
    return -1;
  }
  struct in_addr address;
  memset(&address, 0, sizeof(address));
  memcpy(&address.s_addr, data, 4);
  add(results, address);
  return 0;
}


x86 assembly (clang, -O0):
<process_a_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1090 <ns_rr_type@plt>
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
je     11c0 <process_a_record+0x50>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <process_a_record+0xcd>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <ns_rr_rdata@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <ns_rr_rdlen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
je     1208 <process_a_record+0x98>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
lea    0xe2a(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <process_a_record+0xcd>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1030 <add@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_a_record>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    (%rsi),%edi
call   1090 <ns_rr_type@plt>
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%rax
jne    11d9 <process_a_record+0x69>
mov    0x0(%rbp),%edi
call   1070 <ns_rr_rdata@plt>
mov    %rax,%r14
mov    0x0(%rbp),%edi
call   1060 <ns_rr_rdlen@plt>
cmp    $0x4,%eax
jne    11eb <process_a_record+0x7b>
mov    %rsp,%r15
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
call   1030 <add@plt>
jmp    1205 <process_a_record+0x95>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    0xe17(%rip),%rdi
jmp    11fb <process_a_record+0x8b>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1040 <fputs@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@ns_t_a = global i64 0
@.str = [33 x i8] c"unexpected resource record type\0A\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"malformed resource record\0A\00"
define i32 @process_a_record(i32* %0, i32* %1, %struct.in_addr* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca %struct.in_addr*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca %struct.in_addr
store i32* %0, i32** %5
store i32* %1, i32** %6
store %struct.in_addr* %2, %struct.in_addr** %7
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = call i64 @ns_rr_type(i32 %12)
%14 = load i64, i64* @ns_t_a
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 -1, i32* %4
br label %40
19: ; preds = %3
%20 = load i32*, i32** %6
%21 = load i32, i32* %20
%22 = call i32* @ns_rr_rdata(i32 %21)
store i32* %22, i32** %8
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = call i32 @ns_rr_rdlen(i32 %24)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 4
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 -1, i32* %4
br label %40
31: ; preds = %19
%32 = call i32 @memset(%struct.in_addr* %10, i32 0, i32 4)
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%34 = load i32*, i32** %8
%35 = call i32 @memcpy(i32* %33, i32* %34, i32 4)
%36 = load %struct.in_addr*, %struct.in_addr** %7
%37 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @add(%struct.in_addr* %36, i32 %38)
store i32 0, i32* %4
br label %40
40: ; preds = %31, %28, %16
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@ns_t_a = global i64 0
@.str = [33 x i8] c"unexpected resource record type\0A\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"malformed resource record\0A\00"
define i32 @process_a_record(i32* nocapture readnone %0, i32* nocapture %1, %struct.in_addr* %2) {
%4 = alloca %struct.in_addr
%5 = load i32, i32* %1
%6 = tail call i64 @ns_rr_type(i32 %5)
%7 = load i64, i64* @ns_t_a
%8 = icmp eq i64 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %28
12: ; preds = %3
%13 = load i32, i32* %1
%14 = tail call i32* @ns_rr_rdata(i32 %13)
%15 = load i32, i32* %1
%16 = tail call i32 @ns_rr_rdlen(i32 %15)
%17 = icmp eq i32 %16, 4
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %28
21: ; preds = %12
%22 = bitcast %struct.in_addr* %4 to i8*
%23 = call i32 @memset(%struct.in_addr* %4, i32 0, i32 4)
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
%25 = call i32 @memcpy(i32* %24, i32* %14, i32 4)
%26 = load i32, i32* %24
%27 = call i32 @add(%struct.in_addr* %2, i32 %26)
br label %28
28: ; preds = %18, %21, %9
%29 = phi i32 [ -1, %9 ], [ -1, %18 ], [ 0, %21 ]
ret i32 %29
}