#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 */
long gethostid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  long hid = 0;
  if (argc != 1) {
    printf("No arg\n");
    return -1;
  }
  hid = gethostid();
  if (hid == -1) {
    perror("hostid:");
    return -1;
  }
  hid = hid & 0xffffffff;
  printf("%x\n", hid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1172 <main+0x42>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <main+0x9b>
mov    $0x0,%al
call   1030 <gethostid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    11a0 <main+0x70>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <main+0x9b>
movabs $0xffffffff,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jne    1167 <main+0x27>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <gethostid@plt>
cmp    $0xffffffffffffffff,%rax
je     117c <main+0x3c>
mov    %eax,%esi
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1178 <main+0x38>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe7d(%rip),%rdi
call   1060 <perror@plt>
jmp    1173 <main+0x33>

LLVM IR (-O0):
@.str = [8 x i8] c"No arg\0A\00"
@.str.1 = [8 x i8] c"hostid:\00"
@.str.2 = [4 x i8] c"%x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %22
11: ; preds = %2
%12 = call i64 (...) @gethostid()
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = icmp eq i64 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %22
17: ; preds = %11
%18 = load i64, i64* %6
%19 = and i64 %18, 4294967295
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %20)
store i32 0, i32* %3
br label %22
22: ; preds = %17, %15, %9
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"hostid:\00"
@.str.2 = [4 x i8] c"%x\0A\00"
@str = [7 x i8] c"No arg\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %14
6: ; preds = %2
%7 = tail call i64 (...) @gethostid()
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %14
11: ; preds = %6
%12 = and i64 %7, 4294967295
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %12)
br label %14
14: ; preds = %11, %9, %4
%15 = phi i32 [ -1, %4 ], [ -1, %9 ], [ 0, %11 ]
ret i32 %15
}