#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ NI_NAMEREQD;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ execl(char *, int /*<<< orphan*/ *);
scalar_t__ getnameinfo(struct sockaddr *, int, char *, int,
                       int /*<<< orphan*/ *, int /*<<< orphan*/,
                       int /*<<< orphan*/);
int inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setenv(char *, char *, int);
int main(int argc, char **argv) {
  struct in_addr addr;
  struct sockaddr_in sa;
  char host[1024];
  assert(argc == 2);
  assert(inet_aton(argv[1], &addr) == 1);
  sa.sin_family = AF_INET;
  sa.sin_addr = addr;
  assert(0 == getnameinfo((struct sockaddr *)&sa, sizeof sa, host, sizeof host,
                          NULL, 0, NI_NAMEREQD));
  printf("Lookup result: %s\n\n", host);
  assert(setenv("REMOTE_HOST", host, 1) == 0);
  execl("/bin/bash", NULL);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <inet_aton@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x420(%rbp),%rdx
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    $0x8,%esi
mov    $0x400,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x420(%rbp),%rsi
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
lea    -0x420(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xde6(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <execl@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x420,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0x10(%rsp),%rsi
call   1070 <inet_aton@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1060 <assert@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0x18(%rsp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x18(%rsp),%rdi
lea    0x20(%rsp),%rbx
mov    $0x8,%esi
mov    %rbx,%rdx
mov    $0x400,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <getnameinfo@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
lea    0xe12(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe17(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
lea    0xe01(%rip),%rdi
xor    %esi,%esi
call   1080 <execl@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.sockaddr_in = type { %struct.in_addr, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@NI_NAMEREQD = global i32 0
@.str = [20 x i8] c"Lookup result: %s\0A\0A\00"
@.str.1 = [12 x i8] c"REMOTE_HOST\00"
@.str.2 = [10 x i8] c"/bin/bash\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.in_addr
%6 = alloca %struct.sockaddr_in
%7 = alloca [1024 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 2
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @inet_aton(i8* %14, %struct.in_addr* %5)
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%22 = bitcast %struct.in_addr* %21 to i8*
%23 = bitcast %struct.in_addr* %5 to i8*
%24 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* @NI_NAMEREQD
%27 = call i64 @getnameinfo(%struct.sockaddr* %24, i32 8, i8* %25, i32 1024, i32* null, i32 0, i32 %26)
%28 = icmp eq i64 0, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = call i64 @setenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 1)
%35 = icmp eq i64 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* null)
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.sockaddr_in = type { %struct.in_addr, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@NI_NAMEREQD = global i32 0
@.str = [20 x i8] c"Lookup result: %s\0A\0A\00"
@.str.1 = [12 x i8] c"REMOTE_HOST\00"
@.str.2 = [10 x i8] c"/bin/bash\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = alloca %struct.sockaddr_in
%5 = alloca [1024 x i8]
%6 = bitcast %struct.in_addr* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @inet_aton(i8* %13, %struct.in_addr* %3)
%15 = icmp eq i32 %14, 1
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%22 = load i32, i32* %20
store i32 %22, i32* %21
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%24 = load i32, i32* @NI_NAMEREQD
%25 = call i64 @getnameinfo(%struct.sockaddr* %23, i32 8, i8* %8, i32 1024, i32* null, i32 0, i32 %24)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %8)
%30 = call i64 @setenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 1)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* null)
ret i32 0
}