#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/ *, int);
int get_ipv4_record(struct sockaddr *addr, unsigned char *buffer) {
  struct sockaddr_in *inet_addr;
  if (addr->sa_family != AF_INET)
    return -1;
  inet_addr = (struct sockaddr_in *)addr;
  memcpy(buffer, &inet_addr->sin_addr, 4);
  return 0;
}


x86 assembly (clang, -O0):
<get_ipv4_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2eba(%rip),%rcx
cmp    (%rcx),%rax
je     1143 <get_ipv4_record+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1164 <get_ipv4_record+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ipv4_record>:
push   %rax
mov    %rdi,%rcx
mov    (%rdi),%rdx
mov    0x2eca(%rip),%rdi
mov    $0xffffffff,%eax
cmp    (%rdi),%rdx
jne    113a <get_ipv4_record+0x2a>
mov    %rsi,%rdi
mov    %rcx,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i64 0
define i32 @get_ipv4_record(%struct.sockaddr* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca %struct.sockaddr_in*
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i8* %1, i8** %5
%7 = load %struct.sockaddr*, %struct.sockaddr** %4
%8 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* @AF_INET
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %20
13: ; preds = %2
%14 = load %struct.sockaddr*, %struct.sockaddr** %4
%15 = bitcast %struct.sockaddr* %14 to %struct.sockaddr_in*
store %struct.sockaddr_in* %15, %struct.sockaddr_in** %6
%16 = load i8*, i8** %5
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = call i32 @memcpy(i8* %16, i32* %18, i32 4)
store i32 0, i32* %3
br label %20
20: ; preds = %13, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
define i32 @get_ipv4_record(%struct.sockaddr* %0, i8* %1) {
%3 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @AF_INET
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = bitcast %struct.sockaddr* %0 to i32*
%9 = tail call i32 @memcpy(i8* %1, i32* %8, i32 4)
br label %10
10: ; preds = %2, %7
%11 = phi i32 [ 0, %7 ], [ -1, %2 ]
ret i32 %11
}