#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_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
void get_address_from_caller(struct sockaddr *caller, socklen_t size) {
  if (size == sizeof(struct sockaddr_in)) {
    printf("%s:%u ", inet_ntoa(((struct sockaddr_in *)caller)->sin_addr),
           ntohs(((struct sockaddr_in *)caller)->sin_port));
  }
}


x86 assembly (clang, -O0):
<get_address_from_caller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x8,%rax
jne    117a <get_address_from_caller+0x4a>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_address_from_caller>:
cmp    $0x8,%esi
jne    1166 <get_address_from_caller+0x36>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r14
mov    (%rbx),%edi
call   1050 <ntohs@plt>
lea    0xeab(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
@.str = [7 x i8] c"%s:%u \00"
define void @get_address_from_caller(%struct.sockaddr* %0, i32 %1) {
%3 = alloca %struct.sockaddr*
%4 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = sext i32 %5 to i64
%7 = icmp eq i64 %6, 8
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = load %struct.sockaddr*, %struct.sockaddr** %3
%10 = bitcast %struct.sockaddr* %9 to %struct.sockaddr_in*
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = call i8* @inet_ntoa(i32 %12)
%14 = load %struct.sockaddr*, %struct.sockaddr** %3
%15 = bitcast %struct.sockaddr* %14 to %struct.sockaddr_in*
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @ntohs(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %18)
br label %20
20: ; preds = %8, %2
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"%s:%u \00"
define void @get_address_from_caller(%struct.sockaddr* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 8
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 1, i32 0
%6 = load i32, i32* %5
%7 = tail call i8* @inet_ntoa(i32 %6)
%8 = getelementptr %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @ntohs(i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %10)
br label %12
12: ; preds = %4, %2
ret void
}