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


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    0x2e3b(%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    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <setprogname@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2f(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1223 <main+0x93>
mov    -0x14(%rbp),%eax
sub    $0x3f,%eax
jne    1217 <main+0x87>
jmp    1212 <main+0x82>
jmp    1217 <main+0x87>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11e2 <main+0x52>
mov    0x2db6(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    125e <main+0xce>
mov    $0x0,%al
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12ae <main+0x11e>
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     12a9 <main+0x119>
mov    $0x1,%edi
lea    0xd5c(%rip),%rsi
call   1070 <err@plt>
jmp    12e8 <main+0x158>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
call   1030 <getdomainname@plt>
cmp    $0x0,%rax
je     12d8 <main+0x148>
mov    $0x1,%edi
lea    0xd3b(%rip),%rsi
call   1070 <err@plt>
mov    -0x30(%rbp),%rsi
lea    0xd39(%rip),%rdi
call   1050 <printf@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%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    0x2e3e(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    (%rsi),%rdi
call   10b0 <setprogname@plt>
lea    0xe52(%rip),%rdx
mov    %ebx,%edi
mov    %r12,%rsi
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     1209 <main+0x79>
lea    0xe3c(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11f0 <main+0x60>
mov    0x2dd0(%rip),%rax
mov    (%rax),%r13
sub    %r13d,%ebx
cmp    $0x2,%ebx
jl     1222 <main+0x92>
xor    %eax,%eax
call   1080 <usage@plt>
mov    (%r12,%r13,8),%rbx
test   %rbx,%rbx
jne    125d <main+0xcd>
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <getdomainname@plt>
test   %rax,%rax
je     124c <main+0xbc>
lea    0xdcc(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
lea    0xdc9(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
jmp    1285 <main+0xf5>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <setdomainname@plt>
test   %rax,%rax
je     1285 <main+0xf5>
lea    0xd85(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%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"
@EXIT_SUCCESS = global i32 0
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
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @setprogname(i8* %15)
br label %17
17: ; preds = %27, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %6
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i32, i32* %6
switch i32 %23, label %25 [
i32 63, label %24
]
24: ; preds = %22
br label %25
25: ; preds = %22, %24
%26 = call i32 (...) @usage()
br label %27
27: ; preds = %25
br label %17
28: ; preds = %17
%29 = load i64, i64* @optind
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = sub nsw i64 %31, %29
%33 = trunc i64 %32 to i32
store i32 %33, i32* %4
%34 = load i64, i64* @optind
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 %34
store i8** %36, i8*** %5
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %28
%40 = call i32 (...) @usage()
br label %41
41: ; preds = %39, %28
%42 = load i8**, i8*** %5
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = load i8**, i8*** %5
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %5
%49 = load i8*, i8** %48
%50 = call i32 @strlen(i8* %49)
%51 = call i64 @setdomainname(i8* %47, i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %55
55: ; preds = %53, %45
br label %64
56: ; preds = %41
%57 = trunc i64 %10 to i32
%58 = call i64 @getdomainname(i8* %12, i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %60, %56
%63 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %64
64: ; preds = %62, %55
%65 = load i32, i32* @EXIT_SUCCESS
%66 = call i32 @exit(i32 %65)
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"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @MAXHOSTNAMELEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i8*, i8** %1
%7 = tail call i32 @setprogname(i8* %6)
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %2, %10
%11 = tail call i32 (...) @usage()
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %10
14: ; preds = %10, %2
%15 = load i64, i64* @optind
%16 = trunc i64 %15 to i32
%17 = sub i32 %0, %16
%18 = getelementptr inbounds i8*, i8** %1, i64 %15
%19 = icmp sgt i32 %17, 1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 (...) @usage()
br label %22
22: ; preds = %20, %14
%23 = load i8*, i8** %18
%24 = icmp eq i8* %23, null
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = tail call i32 @strlen(i8* %23)
%27 = tail call i64 @setdomainname(i8* %23, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %25
%30 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %38
31: ; preds = %22
%32 = call i64 @getdomainname(i8* %5, i32 %3)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %38
38: ; preds = %25, %29, %36
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
}