#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 */
typedef int /*<<< orphan*/ time_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct in_addr {
  int dummy;
};
struct hostent {
  char *h_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
char *ctime(int /*<<< orphan*/ *);
struct hostent *gethostbyaddr(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
void socketConnection(int connectfd, struct sockaddr_in clientAddr) {
  struct hostent *hostEntry;
  char *hostName;
  hostEntry =
      gethostbyaddr(&(clientAddr.sin_addr), sizeof(struct in_addr), AF_INET);
  if (hostEntry == NULL)
    herror("gethostbyaddr()");
  hostName = hostEntry->h_name;
  printf("Hostname: %s\n", hostName);
  time_t current_time = time(NULL);
  char *c_time_string = ctime(&current_time);
  write(connectfd, c_time_string, strlen(c_time_string) + 1);
}


x86 assembly (clang, -O0):
<socketConnection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1090 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <socketConnection+0x40>
lea    0xe55(%rip),%rdi
call   1080 <herror@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketConnection>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %esi,(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x4,%esi
call   1090 <gethostbyaddr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a2 <socketConnection+0x32>
lea    0xe63(%rip),%rdi
call   1080 <herror@plt>
mov    (%rbx),%rsi
lea    0xe64(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i8* }
@AF_INET = global i32 0
@.str = [16 x i8] c"gethostbyaddr()\00"
@.str.1 = [14 x i8] c"Hostname: %s\0A\00"
define void @socketConnection(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.hostent*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %1, i32* %9
store i32 %0, i32* %4
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%11 = load i32, i32* @AF_INET
%12 = call %struct.hostent* @gethostbyaddr(i32* %10, i32 4, i32 %11)
store %struct.hostent* %12, %struct.hostent** %5
%13 = load %struct.hostent*, %struct.hostent** %5
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @herror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load %struct.hostent*, %struct.hostent** %5
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @time(i32* null)
store i32 %23, i32* %7
%24 = call i8* @ctime(i32* %7)
store i8* %24, i8** %8
%25 = load i32, i32* %4
%26 = load i8*, i8** %8
%27 = load i8*, i8** %8
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @write(i32 %25, i8* %26, i64 %29)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i8* }
@AF_INET = global i32 0
@.str = [16 x i8] c"gethostbyaddr()\00"
@.str.1 = [14 x i8] c"Hostname: %s\0A\00"
define void @socketConnection(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %1, i32* %5
%6 = load i32, i32* @AF_INET
%7 = call %struct.hostent* @gethostbyaddr(i32* %5, i32 4, i32 %6)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @herror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = bitcast i32* %4 to i8*
%16 = call i32 @time(i32* null)
store i32 %16, i32* %4
%17 = call i8* @ctime(i32* %4)
%18 = call i64 @strlen(i8* dereferenceable(1) %17)
%19 = add nsw i64 %18, 1
%20 = call i32 @write(i32 %0, i8* %17, i64 %19)
ret void
}