#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 /*<<< orphan*/ printf(char *);
int int_ip4(struct sockaddr *addr, uint32_t *ip) {
  if (addr->sa_family == AF_INET) {
    struct sockaddr_in *i = (struct sockaddr_in *)addr;
    *ip = i->sin_addr.s_addr;
    return 0;
  } else {
    printf("Not AF_INET");
    printf("\n");
    ;
    return 1;
  }
}


x86 assembly (clang, -O0):
<int_ip4>:
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
jne    1157 <int_ip4+0x47>
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    1176 <int_ip4+0x66>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_ip4>:
push   %rax
mov    (%rdi),%rax
mov    0x2ebd(%rip),%rcx
cmp    (%rcx),%rax
jne    1136 <int_ip4+0x16>
mov    %eax,(%rsi)
xor    %eax,%eax
pop    %rcx
ret
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%eax
pop    %rcx
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
@.str = [12 x i8] c"Not AF_INET\00"
@.str.1 = [2 x i8] c"\0A\00"
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 %23
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %23
23: ; preds = %20, %12
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@.str = [12 x i8] c"Not AF_INET\00"
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 %12
9: ; preds = %2
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @putchar(i32 10)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ 0, %7 ], [ 1, %9 ]
ret i32 %13
}