#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 hostent {
  char *h_name;
};
typedef int /*<<< orphan*/ host;

/* Variables and functions */
struct hostent *gethostbyname(char *);
int gethostname(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char host[16] = {0};
  struct hostent *hostent = NULL;
  int rs = gethostname(host, sizeof(host));
  if (rs == 0) {
    hostent = gethostbyname(host);
    if (hostent) {
      printf("%s\n", host);
      printf("%s\n", hostent->h_name);
    }
  } else if (rs == -1) {
    printf("gethostname error\n");
  } else {
    printf("other error\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movq   $0x0,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
call   1060 <gethostname@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11c6 <main+0x86>
lea    -0x20(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c1 <main+0x81>
lea    -0x20(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <main+0xb6>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11e3 <main+0xa3>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <main+0xb1>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <main+0xb6>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x10,%esi
call   1050 <gethostname@plt>
cmp    $0xffffffff,%eax
je     116f <main+0x3f>
test   %eax,%eax
jne    1178 <main+0x48>
mov    %rsp,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1184 <main+0x54>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
jmp    117f <main+0x4f>
lea    0xe96(%rip),%rdi
jmp    117f <main+0x4f>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [19 x i8] c"gethostname error\0A\00"
@.str.2 = [13 x i8] c"other error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca %struct.hostent*
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [16 x i8]* %2 to i8*
store %struct.hostent* null, %struct.hostent** %3
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = call i32 @gethostname(i8* %6, i32 16)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%12 = call %struct.hostent* @gethostbyname(i8* %11)
store %struct.hostent* %12, %struct.hostent** %3
%13 = load %struct.hostent*, %struct.hostent** %3
%14 = icmp ne %struct.hostent* %13, null
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load %struct.hostent*, %struct.hostent** %3
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %15, %10
br label %31
23: ; preds = %0
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %30
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
br label %31
31: ; preds = %30, %22
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i8* }
@str = [12 x i8] c"other error\00"
@str.3 = [18 x i8] c"gethostname error\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = call i32 @gethostname(i8* %2, i32 16)
switch i32 %3, label %11 [
i32 0, label %4
i32 -1, label %12
]
4: ; preds = %0
%5 = call %struct.hostent* @gethostbyname(i8* %2)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = call i32 @puts(i8* %2)
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%10 = load i8*, i8** %9
br label %12
11: ; preds = %0
br label %12
12: ; preds = %0, %7, %11
%13 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), %11 ], [ %10, %7 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0), %0 ]
%14 = call i32 @puts(i8* dereferenceable(1) %13)
br label %15
15: ; preds = %12, %4
ret i32 0
}