#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*/ hostname;

/* Variables and functions */
int MAXHOSTNAMELEN;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ gethostname(char *, int);
int getopt(int, char **, char *);
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ sethostname(char *, int);
char *strchr(char *, char);
scalar_t__ strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int ch, sflag;
  char *p, hostname[MAXHOSTNAMELEN];
  sflag = 0;
  while ((ch = getopt(argc, argv, "fs")) != -1)
    switch (ch) {
    case 'f':
      break;
    case 's':
      sflag = 1;
      break;
    case '?':
    default:
      usage();
    }
  argc -= optind;
  argv += optind;
  if (argc > 1)
    usage();
  if (*argv) {
    if (sethostname(*argv, (int)strlen(*argv)))
      err(1, "sethostname");
  } else {
    if (gethostname(hostname, (int)sizeof(hostname)))
      err(1, "gethostname");
    if (sflag) {
      p = strchr(hostname, '.');
      if (p != NULL)
        *p = '\0';
    }
    (void)printf("%s\n", hostname);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1254 <main+0xc4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x3f,%eax
je     1243 <main+0xb3>
jmp    1210 <main+0x80>
mov    -0x44(%rbp),%eax
sub    $0x66,%eax
je     1232 <main+0xa2>
jmp    1221 <main+0x91>
mov    -0x44(%rbp),%eax
sub    $0x73,%eax
je     1237 <main+0xa7>
jmp    1248 <main+0xb8>
jmp    124f <main+0xbf>
movl   $0x1,-0x18(%rbp)
jmp    124f <main+0xbf>
jmp    1248 <main+0xb8>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11dd <main+0x4d>
mov    0x2d85(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d71(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    128f <main+0xff>
mov    $0x0,%al
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12df <main+0x14f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1060 <sethostname@plt>
cmp    $0x0,%rax
je     12da <main+0x14a>
mov    $0x1,%edi
lea    0xd2e(%rip),%rsi
call   1070 <err@plt>
jmp    134c <main+0x1bc>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
call   10a0 <gethostname@plt>
cmp    $0x0,%rax
je     1309 <main+0x179>
mov    $0x1,%edi
lea    0xd0b(%rip),%rsi
call   1070 <err@plt>
cmpl   $0x0,-0x18(%rbp)
je     133c <main+0x1ac>
mov    -0x38(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1337 <main+0x1a7>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    133c <main+0x1ac>
mov    -0x38(%rbp),%rsi
lea    0xcd4(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <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),%eax
mov    %rsp,%r15
mov    %rax,-0x30(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    $0x1,%r14b
lea    0xe35(%rip),%r13
jmp    11d0 <main+0x40>
xor    %r14d,%r14d
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
cmp    $0x66,%eax
je     11d0 <main+0x40>
cmp    $0x73,%eax
je     11cd <main+0x3d>
cmp    $0xffffffff,%eax
je     11f5 <main+0x65>
xor    %eax,%eax
call   1080 <usage@plt>
jmp    11d0 <main+0x40>
mov    0x2de4(%rip),%rax
mov    (%rax),%r13
sub    %r13d,%ebx
cmp    $0x2,%ebx
jl     120e <main+0x7e>
xor    %eax,%eax
call   1080 <usage@plt>
mov    (%r12,%r13,8),%rbx
test   %rbx,%rbx
jne    1265 <main+0xd5>
mov    %r15,%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <gethostname@plt>
test   %rax,%rax
je     1239 <main+0xa9>
lea    0xde0(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
test   $0x1,%r14b
jne    1254 <main+0xc4>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1254 <main+0xc4>
movb   $0x0,(%rax)
lea    0xdc0(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
jmp    127c <main+0xec>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <sethostname@plt>
test   %rax,%rax
jne    1283 <main+0xf3>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd79(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@MAXHOSTNAMELEN = global i32 0
@.str = [3 x i8] c"fs\00"
@optind = global i64 0
@.str.1 = [12 x i8] c"sethostname\00"
@.str.2 = [12 x i8] c"gethostname\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 i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @MAXHOSTNAMELEN
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
store i32 0, i32* %7
br label %15
15: ; preds = %27, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %6
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load i32, i32* %6
switch i32 %21, label %25 [
i32 102, label %22
i32 115, label %23
i32 63, label %24
]
22: ; preds = %20
br label %27
23: ; preds = %20
store i32 1, i32* %7
br label %27
24: ; preds = %20
br label %25
25: ; preds = %20, %24
%26 = call i32 (...) @usage()
br label %27
27: ; preds = %25, %23, %22
br label %15
28: ; preds = %15
%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 %57
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 i64 @strlen(i8* %49)
%51 = trunc i64 %50 to i32
%52 = call i64 @sethostname(i8* %47, i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %45
%55 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %56
56: ; preds = %54, %45
br label %75
57: ; preds = %41
%58 = trunc i64 %12 to i32
%59 = call i64 @gethostname(i8* %14, i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %61, %57
%64 = load i32, i32* %7
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %73
66: ; preds = %63
%67 = call i8* @strchr(i8* %14, i8 signext 46)
store i8* %67, i8** %8
%68 = load i8*, i8** %8
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = load i8*, i8** %8
store i8 0, i8* %71
br label %72
72: ; preds = %70, %66
br label %73
73: ; preds = %72, %63
%74 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %75
75: ; preds = %73, %56
%76 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@MAXHOSTNAMELEN = global i32 0
@.str = [3 x i8] c"fs\00"
@optind = global i64 0
@.str.1 = [12 x i8] c"sethostname\00"
@.str.2 = [12 x i8] c"gethostname\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
br label %6
6: ; preds = %8, %2
%7 = phi i1 [ true, %2 ], [ false, %8 ]
br label %8
8: ; preds = %10, %6
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %11 [
i32 -1, label %13
i32 102, label %10
i32 115, label %6
]
10: ; preds = %8, %11
br label %8
11: ; preds = %8
%12 = tail call i32 (...) @usage()
br label %10
13: ; preds = %8
%14 = load i64, i64* @optind
%15 = trunc i64 %14 to i32
%16 = sub i32 %0, %15
%17 = getelementptr inbounds i8*, i8** %1, i64 %14
%18 = icmp sgt i32 %16, 1
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 (...) @usage()
br label %21
21: ; preds = %19, %13
%22 = load i8*, i8** %17
%23 = icmp eq i8* %22, null
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = tail call i64 @strlen(i8* %22)
%26 = trunc i64 %25 to i32
%27 = tail call i64 @sethostname(i8* %22, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %43, label %29
29: ; preds = %24
%30 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %43
31: ; preds = %21
%32 = call i64 @gethostname(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 ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
br i1 %7, label %41, label %37
37: ; preds = %36
%38 = call i8* @strchr(i8* %5, i8 signext 46)
%39 = icmp eq i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %37
store i8 0, i8* %38
br label %41
41: ; preds = %37, %40, %36
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %43
43: ; preds = %24, %29, %41
%44 = call i32 @exit(i32 0)
unreachable
}