#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 {
  int dummy;
};
typedef int /*<<< orphan*/ name;

/* Variables and functions */
struct hostent *gethostbyname(char *);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char name[100];
  struct hostent *hp;
  if (gethostname(name, sizeof(name)) < 0) {
    perror("gethostname error");
    return -1;
  }
  printf("hostname: %s\n", name);
  hp = gethostbyname(name);
  if (hp == NULL) {
    herror("gethostbyname error");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
call   1070 <gethostname@plt>
cmp    $0x0,%rax
jge    1192 <main+0x42>
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <main+0x89>
lea    -0x70(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11d2 <main+0x82>
lea    0xe5f(%rip),%rdi
call   1050 <herror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <main+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
mov    %rsp,%rdi
mov    $0x64,%esi
call   1070 <gethostname@plt>
test   %rax,%rax
js     11a2 <main+0x52>
lea    0xea4(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    119c <main+0x4c>
lea    0xe8e(%rip),%rdi
call   1050 <herror@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbx
ret
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
jmp    1197 <main+0x47>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@.str = [18 x i8] c"gethostname error\00"
@.str.1 = [14 x i8] c"hostname: %s\0A\00"
@.str.2 = [20 x i8] c"gethostbyname error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca %struct.hostent*
store i32 0, i32* %1
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i64 @gethostname(i8* %4, i32 100)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %19
9: ; preds = %0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call %struct.hostent* @gethostbyname(i8* %12)
store %struct.hostent* %13, %struct.hostent** %3
%14 = load %struct.hostent*, %struct.hostent** %3
%15 = icmp eq %struct.hostent* %14, null
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @herror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %19
18: ; preds = %9
store i32 0, i32* %1
br label %19
19: ; preds = %18, %16, %7
%20 = load i32, i32* %1
ret i32 %20
}

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