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

/* Variables and functions */
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
void sys_who_called(struct sockaddr_in *p) {
  char host[1024];
  strncpy(host, inet_ntoa(p->sin_addr), 1024);
  printf("from %s: %d\n", host, ntohs(p->sin_port));
}


x86 assembly (clang, -O0):
<sys_who_called>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x420(%rbp),%rdi
mov    %eax,%esi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
lea    0xe5b(%rip),%rdi
call   1050 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_who_called>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1040 <inet_ntoa@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x400,%edx
call   1030 <strncpy@plt>
mov    (%rbx),%edi
call   1060 <ntohs@plt>
lea    0xe8b(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
@.str = [13 x i8] c"from %s: %d\0A\00"
define void @sys_who_called(%struct.sockaddr_in* %0) {
%2 = alloca %struct.sockaddr_in*
%3 = alloca [1024 x i8]
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %2
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%7 = load i32, i32* %6
%8 = call i32 @inet_ntoa(i32 %7)
%9 = call i32 @strncpy(i8* %4, i32 %8, i32 1024)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @ntohs(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %14)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
@.str = [13 x i8] c"from %s: %d\0A\00"
define void @sys_who_called(%struct.sockaddr_in* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = tail call i32 @inet_ntoa(i32 %5)
%7 = call i32 @strncpy(i8* %3, i32 %6, i32 1024)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @ntohs(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %10)
ret void
}