#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 MAXHOSTNAMELEN;
int /*<<< orphan*/ exit(int);
scalar_t__ geteuid();
int /*<<< orphan*/ gethostname(char *, int);
scalar_t__ getuid();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sethostname(char *, int);
int strlen(char *);
int main(int argc, char *argv[]) {
  char hn[MAXHOSTNAMELEN + 1];
  if (argc >= 2) {
    if (geteuid() || getuid()) {
      puts("You must be root to change the hostname");
      exit(1);
    }
    if (strlen(argv[1]) > MAXHOSTNAMELEN) {
      puts("That name is too long.");
      exit(1);
    }
    sethostname(argv[1], strlen(argv[1]));
  } else {
    gethostname(hn, MAXHOSTNAMELEN);
    puts(hn);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1252 <main+0xe2>
mov    $0x0,%al
call   1060 <geteuid@plt>
cmp    $0x0,%rax
jne    11e1 <main+0x71>
mov    $0x0,%al
call   1050 <getuid@plt>
cmp    $0x0,%rax
je     11f7 <main+0x87>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%eax
jle    1229 <main+0xb9>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1070 <sethostname@plt>
jmp    126d <main+0xfd>
mov    -0x28(%rbp),%rdi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
call   1080 <gethostname@plt>
mov    -0x28(%rbp),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e64(%rip),%r15
mov    (%r15),%esi
lea    0x1(%rsi),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jl     11cf <main+0x5f>
xor    %eax,%eax
call   1060 <geteuid@plt>
test   %rax,%rax
jne    11e6 <main+0x76>
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
jne    11e6 <main+0x76>
mov    0x8(%r14),%rdi
call   1040 <strlen@plt>
cmp    (%r15),%eax
jle    11fc <main+0x8c>
lea    0xe5b(%rip),%rdi
jmp    11ed <main+0x7d>
mov    %rbx,%rdi
call   1080 <gethostname@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <sethostname@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@MAXHOSTNAMELEN = global i32 0
@.str = [40 x i8] c"You must be root to change the hostname\00"
@.str.1 = [23 x i8] c"That name is too long.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @MAXHOSTNAMELEN
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 2
br i1 %14, label %15, label %43
15: ; preds = %2
%16 = call i64 (...) @geteuid()
%17 = icmp ne i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i64 (...) @getuid()
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %15
%22 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
%29 = load i32, i32* @MAXHOSTNAMELEN
%30 = icmp sgt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strlen(i8* %40)
%42 = call i32 @sethostname(i8* %37, i32 %41)
br label %47
43: ; preds = %2
%44 = load i32, i32* @MAXHOSTNAMELEN
%45 = call i32 @gethostname(i8* %12, i32 %44)
%46 = call i32 @puts(i8* %12)
br label %47
47: ; preds = %43, %34
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@MAXHOSTNAMELEN = global i32 0
@.str = [40 x i8] c"You must be root to change the hostname\00"
@.str.1 = [23 x i8] c"That name is too long.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @MAXHOSTNAMELEN
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %30
8: ; preds = %2
%9 = tail call i64 (...) @geteuid()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i64 (...) @getuid()
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11, %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @strlen(i8* %19)
%21 = load i32, i32* @MAXHOSTNAMELEN
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = load i8*, i8** %18
%28 = tail call i32 @strlen(i8* %27)
%29 = tail call i32 @sethostname(i8* %27, i32 %28)
br label %33
30: ; preds = %2
%31 = call i32 @gethostname(i8* %6, i32 %3)
%32 = call i32 @puts(i8* %6)
br label %33
33: ; preds = %30, %26
%34 = call i32 @exit(i32 0)
unreachable
}