#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;
};
struct passwd {
  int /*<<< orphan*/ pw_name;
};
struct in_addr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_name;
};
typedef int /*<<< orphan*/ remotehost;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ endhostent();
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ logwtmp(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
void dologin(struct passwd *pw, struct sockaddr_in *sin) {
  char line[32];
  char remotehost[32];
  int f;
  struct hostent *hp =
      gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET);
  if (hp) {
    strncpy(remotehost, hp->h_name, sizeof(remotehost));
    endhostent();
  } else
    strncpy(remotehost, inet_ntoa(sin->sin_addr), sizeof(remotehost));
  sprintf(line, "uucp%.4d", getpid());
  logwtmp(line, pw->pw_name, remotehost);
}


x86 assembly (clang, -O0):
<dologin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1070 <gethostbyaddr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     11c6 <dologin+0x56>
lea    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    (%rax),%esi
mov    $0x20,%edx
call   1030 <strncpy@plt>
mov    $0x0,%al
call   1090 <endhostent@plt>
jmp    11e9 <dologin+0x79>
lea    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <inet_ntoa@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
mov    $0x20,%edx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%edx
lea    0xdfb(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1040 <logwtmp@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dologin>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    %rsi,%rdi
mov    $0x4,%esi
call   1070 <gethostbyaddr@plt>
test   %rax,%rax
je     11b0 <dologin+0x40>
mov    (%rax),%esi
mov    %rsp,%rdi
mov    $0x20,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
call   1090 <endhostent@plt>
jmp    11c6 <dologin+0x56>
mov    (%rbx),%edi
call   1060 <inet_ntoa@plt>
mov    %rsp,%rdi
mov    %eax,%esi
mov    $0x20,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe2c(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <sprintf@plt>
mov    (%r14),%esi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1040 <logwtmp@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@.str = [9 x i8] c"uucp%.4d\00"
define void @dologin(%struct.passwd* %0, %struct.sockaddr_in* %1) {
%3 = alloca %struct.passwd*
%4 = alloca %struct.sockaddr_in*
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca %struct.hostent*
store %struct.passwd* %0, %struct.passwd** %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%11 = bitcast i32* %10 to i8*
%12 = load i32, i32* @AF_INET
%13 = call %struct.hostent* @gethostbyaddr(i8* %11, i32 4, i32 %12)
store %struct.hostent* %13, %struct.hostent** %8
%14 = load %struct.hostent*, %struct.hostent** %8
%15 = icmp ne %struct.hostent* %14, null
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%18 = load %struct.hostent*, %struct.hostent** %8
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strncpy(i8* %17, i32 %20, i32 32)
%22 = call i32 (...) @endhostent()
br label %30
23: ; preds = %2
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @inet_ntoa(i32 %27)
%29 = call i32 @strncpy(i8* %24, i32 %28, i32 32)
br label %30
30: ; preds = %23, %16
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%32 = call i32 (...) @getpid()
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%35 = load %struct.passwd*, %struct.passwd** %3
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%39 = call i32 @logwtmp(i8* %34, i32 %37, i8* %38)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@.str = [9 x i8] c"uucp%.4d\00"
define void @dologin(%struct.passwd* nocapture %0, %struct.sockaddr_in* %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %1 to i8*
%8 = load i32, i32* @AF_INET
%9 = tail call %struct.hostent* @gethostbyaddr(i8* %7, i32 4, i32 %8)
%10 = icmp eq %struct.hostent* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @strncpy(i8* %6, i32 %13, i32 32)
%15 = call i32 (...) @endhostent()
br label %21
16: ; preds = %2
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i32 @inet_ntoa(i32 %18)
%20 = call i32 @strncpy(i8* %6, i32 %19, i32 32)
br label %21
21: ; preds = %16, %11
%22 = call i32 (...) @getpid()
%23 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @logwtmp(i8* %5, i32 %25, i8* %6)
ret void
}