#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;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
int errno;
int int_ip4(struct sockaddr *addr, uint32_t *ip) {
  if (addr->sa_family == AF_INET) {
    struct sockaddr_in *ip_sock = (struct sockaddr_in *)addr;
    *ip = ip_sock->sin_addr.s_addr;
    return 0;
  } else {
    errno = -6;
    return -1;
  }
}


x86 assembly (clang, -O0):
<int_ip4>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2ece(%rip),%rcx
cmp    (%rcx),%rax
jne    1143 <int_ip4+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1157 <int_ip4+0x57>
mov    0x2e8e(%rip),%rax
movl   $0xfffffffa,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_ip4>:
mov    (%rdi),%rax
mov    0x2ede(%rip),%rcx
cmp    (%rcx),%rax
jne    1114 <int_ip4+0x14>
mov    %eax,(%rsi)
xor    %eax,%eax
ret
mov    0x2ebd(%rip),%rax
movl   $0xfffffffa,(%rax)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i64 0
@errno = global i32 0
define i32 @int_ip4(%struct.sockaddr* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca i32*
%6 = alloca %struct.sockaddr_in*
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i32* %1, i32** %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 eq i64 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load %struct.sockaddr*, %struct.sockaddr** %4
%14 = bitcast %struct.sockaddr* %13 to %struct.sockaddr_in*
store %struct.sockaddr_in* %14, %struct.sockaddr_in** %6
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i32*, i32** %5
store i32 %18, i32* %19
store i32 0, i32* %3
br label %21
20: ; preds = %2
store i32 -6, i32* @errno
store i32 -1, i32* %3
br label %21
21: ; preds = %20, %12
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@errno = global i32 0
define i32 @int_ip4(%struct.sockaddr* nocapture %0, i32* nocapture writeonly %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 %9
7: ; preds = %2
%8 = trunc i64 %4 to i32
store i32 %8, i32* %1
br label %10
9: ; preds = %2
store i32 -6, i32* @errno
br label %10
10: ; preds = %9, %7
%11 = phi i32 [ 0, %7 ], [ -1, %9 ]
ret i32 %11
}