#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 */
typedef int /*<<< orphan*/ domainname;

/* Variables and functions */
int MAXHOSTNAMELEN;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getdomainname(char *, int);
int getopt(int, char **, char *);
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setdomainname(char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int ch;
  char domainname[MAXHOSTNAMELEN];
  while ((ch = getopt(argc, argv, "")) != -1)
    switch (ch) {
    case '?':
    default:
      usage();
    }
  argc -= optind;
  argv += optind;
  if (argc > 1)
    usage();
  if (*argv) {
    if (setdomainname(*argv, (int)strlen(*argv)))
      err(1, "setdomainname");
  } else {
    if (getdomainname(domainname, (int)sizeof(domainname)))
      err(1, "getdomainname");
    (void)printf("%s\n", domainname);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1207 <main+0x87>
mov    -0x14(%rbp),%eax
sub    $0x3f,%eax
jne    11fb <main+0x7b>
jmp    11f6 <main+0x76>
jmp    11fb <main+0x7b>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11c6 <main+0x46>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1242 <main+0xc2>
mov    $0x0,%al
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1292 <main+0x112>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1060 <setdomainname@plt>
cmp    $0x0,%rax
je     128d <main+0x10d>
mov    $0x1,%edi
lea    0xd78(%rip),%rsi
call   1070 <err@plt>
jmp    12cc <main+0x14c>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
call   1030 <getdomainname@plt>
cmp    $0x0,%rax
je     12bc <main+0x13c>
mov    $0x1,%edi
lea    0xd57(%rip),%rsi
call   1070 <err@plt>
mov    -0x30(%rbp),%rsi
lea    0xd55(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x2e4e(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe6a(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11e9 <main+0x69>
lea    0xe59(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x50>
mov    0x2df0(%rip),%rax
mov    (%rax),%r13
sub    %r13d,%ebx
cmp    $0x2,%ebx
jl     1202 <main+0x82>
xor    %eax,%eax
call   1080 <usage@plt>
mov    (%r12,%r13,8),%rbx
test   %rbx,%rbx
jne    123d <main+0xbd>
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <getdomainname@plt>
test   %rax,%rax
je     122c <main+0xac>
lea    0xdec(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
lea    0xde9(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
jmp    1254 <main+0xd4>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <setdomainname@plt>
test   %rax,%rax
jne    125b <main+0xdb>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xd9e(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@MAXHOSTNAMELEN = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@.str.1 = [14 x i8] c"setdomainname\00"
@.str.2 = [14 x i8] c"getdomainname\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @MAXHOSTNAMELEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %7
%12 = alloca i8, i64 %10
store i64 %10, i64* %8
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i32, i32* %6
switch i32 %19, label %21 [
i32 63, label %20
]
20: ; preds = %18
br label %21
21: ; preds = %18, %20
%22 = call i32 (...) @usage()
br label %23
23: ; preds = %21
br label %13
24: ; preds = %13
%25 = load i64, i64* @optind
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = sub nsw i64 %27, %25
%29 = trunc i64 %28 to i32
store i32 %29, i32* %4
%30 = load i64, i64* @optind
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 %30
store i8** %32, i8*** %5
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 1
br i1 %34, label %35, label %37
35: ; preds = %24
%36 = call i32 (...) @usage()
br label %37
37: ; preds = %35, %24
%38 = load i8**, i8*** %5
%39 = load i8*, i8** %38
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i8**, i8*** %5
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %5
%45 = load i8*, i8** %44
%46 = call i64 @strlen(i8* %45)
%47 = trunc i64 %46 to i32
%48 = call i64 @setdomainname(i8* %43, i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %50, %41
br label %61
53: ; preds = %37
%54 = trunc i64 %10 to i32
%55 = call i64 @getdomainname(i8* %12, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %61
61: ; preds = %59, %52
%62 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@MAXHOSTNAMELEN = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@.str.1 = [14 x i8] c"setdomainname\00"
@.str.2 = [14 x i8] c"getdomainname\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @MAXHOSTNAMELEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %2, %8
%9 = tail call i32 (...) @usage()
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %8
12: ; preds = %8, %2
%13 = load i64, i64* @optind
%14 = trunc i64 %13 to i32
%15 = sub i32 %0, %14
%16 = getelementptr inbounds i8*, i8** %1, i64 %13
%17 = icmp sgt i32 %15, 1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 (...) @usage()
br label %20
20: ; preds = %18, %12
%21 = load i8*, i8** %16
%22 = icmp eq i8* %21, null
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = tail call i64 @strlen(i8* %21)
%25 = trunc i64 %24 to i32
%26 = tail call i64 @setdomainname(i8* %21, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %37, label %28
28: ; preds = %23
%29 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %37
30: ; preds = %20
%31 = call i64 @getdomainname(i8* %5, i32 %3)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %37
37: ; preds = %23, %28, %35
%38 = call i32 @exit(i32 0)
unreachable
}