#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 */
scalar_t__ getdomainname(char *, int);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  char name[1024] = "";
  if (gethostname(name, 1024) != 0) {
    perror("gethostname");
    return 1;
  }
  printf("hostname is: %s\n", name);
  if (getdomainname(name, 1024) != 0) {
    perror("getdomainname");
    return 1;
  }
  printf("domain name is: %s\n", name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1070 <gethostname@plt>
cmp    $0x0,%rax
je     11a8 <main+0x58>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1208 <main+0xb8>
lea    -0x410(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1030 <getdomainname@plt>
cmp    $0x0,%rax
je     11ee <main+0x9e>
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1208 <main+0xb8>
lea    -0x410(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <gethostname@plt>
test   %rax,%rax
jne    11ba <main+0x6a>
lea    0xe89(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1030 <getdomainname@plt>
test   %rax,%rax
jne    11c3 <main+0x73>
lea    0xe84(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret
lea    0xe3f(%rip),%rdi
jmp    11ca <main+0x7a>
lea    0xe53(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    11b1 <main+0x61>

LLVM IR (-O0):
@.str = [12 x i8] c"gethostname\00"
@.str.1 = [17 x i8] c"hostname is: %s\0A\00"
@.str.2 = [14 x i8] c"getdomainname\00"
@.str.3 = [20 x i8] c"domain name is: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
store i32 0, i32* %1
%3 = bitcast [1024 x i8]* %2 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i64 @gethostname(i8* %4, i32 1024)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %20
9: ; preds = %0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%11 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = call i64 @getdomainname(i8* %12, i32 1024)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %20
17: ; preds = %9
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %18)
store i32 0, i32* %1
br label %20
20: ; preds = %17, %15, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [12 x i8] c"gethostname\00"
@.str.1 = [17 x i8] c"hostname is: %s\0A\00"
@.str.2 = [14 x i8] c"getdomainname\00"
@.str.3 = [20 x i8] c"domain name is: %s\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i64 @gethostname(i8* %2, i32 1024)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%9 = call i64 @getdomainname(i8* %2, i32 1024)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %15
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %15
15: ; preds = %13, %11, %5
%16 = phi i32 [ 1, %5 ], [ 1, %11 ], [ 0, %13 ]
ret i32 %16
}