#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 */

/* Variables and functions */
int /*<<< orphan*/ __nss_configure_lookup(char *, char *);
int /*<<< orphan*/ free(char *);
char *get_services();
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
void __attribute__((constructor)) nss_tld_mapper_init() {
  char *services = get_services();
  char *service_line =
      malloc((strlen(services) + strlen("tld_mapper") + 2) * sizeof(char));
  sprintf(service_line, "%s %s", services, "tld_mapper");
  __nss_configure_lookup("hosts", service_line);
  free(service_line);
}


x86 assembly (clang, -O0):
<nss_tld_mapper_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <get_services@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
lea    0xe7a(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe56(%rip),%rsi
lea    0xe44(%rip),%rcx
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe45(%rip),%rdi
call   1050 <__nss_configure_lookup@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nss_tld_mapper_init>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <get_services@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
lea    0xe7c(%rip),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe69(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
call   1080 <sprintf@plt>
lea    0xe5a(%rip),%rdi
mov    %rbx,%rsi
call   1050 <__nss_configure_lookup@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <free@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"tld_mapper\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [6 x i8] c"hosts\00"
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @nss_tld_mapper_init, i8* null }]
define void @nss_tld_mapper_init() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* (...) @get_services()
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = call i32 @strlen(i8* %4)
%6 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = add nsw i32 %5, %6
%8 = add nsw i32 %7, 2
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = load i8*, i8** %1
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %2
%17 = call i32 @__nss_configure_lookup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %2
%19 = call i32 @free(i8* %18)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"tld_mapper\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [6 x i8] c"hosts\00"
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @nss_tld_mapper_init, i8* null }]
define void @nss_tld_mapper_init() {
%1 = tail call i8* (...) @get_services()
%2 = tail call i32 @strlen(i8* %1)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = add i32 %2, 2
%5 = add i32 %4, %3
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @__nss_configure_lookup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%9 = tail call i32 @free(i8* %6)
ret void
}