#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void ip4() {
  struct sockaddr_in sa4;
  inet_pton(AF_INET, "192.0.2.1", &(sa4.sin_addr));
  char ip4[INET_ADDRSTRLEN];
  inet_ntop(AF_INET, &(sa4.sin_addr), ip4, INET_ADDRSTRLEN);
  printf("round-tripped ip4: %s\n", ip4);
}


x86 assembly (clang, -O0):
<ip4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <inet_pton@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
mov    0x2e47(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    -0x20(%rbp),%rsi
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip4>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2ea2(%rip),%r15
mov    (%r15),%edi
lea    0xeb0(%rip),%rsi
lea    -0x28(%rbp),%r14
mov    %r14,%rdx
call   1050 <inet_pton@plt>
mov    %rsp,%r12
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%r15),%edi
mov    (%rax),%ecx
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
lea    0xe7a(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r12,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"192.0.2.1\00"
@INET_ADDRSTRLEN = global i32 0
@.str.1 = [23 x i8] c"round-tripped ip4: %s\0A\00"
define void @ip4() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i8*
%3 = alloca i64
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
%6 = call i32 @inet_pton(i32 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %5)
%7 = load i32, i32* @INET_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %2
%10 = alloca i8, i64 %8
store i64 %8, i64* %3
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
%13 = load i32, i32* @INET_ADDRSTRLEN
%14 = call i32 @inet_ntop(i32 %11, i32* %12, i8* %10, i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%16 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"192.0.2.1\00"
@INET_ADDRSTRLEN = global i32 0
@.str.1 = [23 x i8] c"round-tripped ip4: %s\0A\00"
define void @ip4() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%5 = call i32 @inet_pton(i32 %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %4)
%6 = load i32, i32* @INET_ADDRSTRLEN
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @INET_ADDRSTRLEN
%12 = call i32 @inet_ntop(i32 %10, i32* %4, i8* %9, i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %9)
ret void
}