#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ gethostname(char *, size_t);
int /*<<< orphan*/ llmnr_set_hostname(char *);
int /*<<< orphan*/ stdout;
scalar_t__ strncmp(char *, char *, size_t);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *xzalloc(size_t);
void hostname_change_handle(char *hostname, size_t maxlen) {
  char *newname;
  newname = xzalloc(maxlen);
  if (gethostname(newname, maxlen) == 0) {
    newname[maxlen - 1] = '\0';
    if (strncmp(hostname, newname, maxlen) != 0) {
      fprintf(stdout, "Hostname changed to %s\n", newname);
      strncpy(hostname, newname, maxlen);
      llmnr_set_hostname(hostname);
    }
  }
  free(newname);
}


x86 assembly (clang, -O0):
<hostname_change_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <xzalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <gethostname@plt>
cmp    $0x0,%rax
jne    1207 <hostname_change_handle+0x97>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     1202 <hostname_change_handle+0x92>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe1d(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1060 <llmnr_set_hostname@plt>
jmp    1207 <hostname_change_handle+0x97>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hostname_change_handle>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1080 <xzalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1090 <gethostname@plt>
test   %rax,%rax
jne    11dd <hostname_change_handle+0x6d>
movb   $0x0,-0x1(%r15,%rbx,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <strncmp@plt>
test   %rax,%rax
je     11dd <hostname_change_handle+0x6d>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <strncpy@plt>
mov    %r14,%rdi
call   1060 <llmnr_set_hostname@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [24 x i8] c"Hostname changed to %s\0A\00"
define void @hostname_change_handle(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = call i8* @xzalloc(i64 %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = load i64, i64* %4
%10 = call i64 @gethostname(i8* %8, i64 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i64, i64* %4
%15 = sub i64 %14, 1
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 0, i8* %16
%17 = load i8*, i8** %3
%18 = load i8*, i8** %5
%19 = load i64, i64* %4
%20 = call i64 @strncmp(i8* %17, i8* %18, i64 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %12
%23 = load i32, i32* @stdout
%24 = load i8*, i8** %5
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %3
%27 = load i8*, i8** %5
%28 = load i64, i64* %4
%29 = call i32 @strncpy(i8* %26, i8* %27, i64 %28)
%30 = load i8*, i8** %3
%31 = call i32 @llmnr_set_hostname(i8* %30)
br label %32
32: ; preds = %22, %12
br label %33
33: ; preds = %32, %2
%34 = load i8*, i8** %5
%35 = call i32 @free(i8* %34)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [24 x i8] c"Hostname changed to %s\0A\00"
define void @hostname_change_handle(i8* %0, i64 %1) {
%3 = tail call i8* @xzalloc(i64 %1)
%4 = tail call i64 @gethostname(i8* %3, i64 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = add i64 %1, -1
%8 = getelementptr inbounds i8, i8* %3, i64 %7
store i8 0, i8* %8
%9 = tail call i64 @strncmp(i8* %0, i8* %3, i64 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %6
%12 = load i32, i32* @stdout
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %3)
%14 = tail call i32 @strncpy(i8* %0, i8* %3, i64 %1)
%15 = tail call i32 @llmnr_set_hostname(i8* %0)
br label %16
16: ; preds = %6, %11, %2
%17 = tail call i32 @free(i8* %3)
ret void
}