#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 /*<<< orphan*/ 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 /*<<< orphan*/);
int /*<<< orphan*/ setprogname(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int ch, sflag;
  char *p, hostname[MAXHOSTNAMELEN + 1];
  setprogname(argv[0]);
  sflag = 0;
  while ((ch = getopt(argc, argv, "s")) != -1)
    switch (ch) {
    case 's':
      sflag = 1;
      break;
    case '?':
    default:
      usage();
    }
  argc -= optind;
  argv += optind;
  if (argc > 1)
    usage();
  if (*argv) {
    if (sethostname(*argv, strlen(*argv)))
      err(1, "sethostname");
  } else {
    if (gethostname(hostname, sizeof(hostname)))
      err(1, "gethostname");
    hostname[sizeof(hostname) - 1] = '\0';
    if (sflag && (p = strchr(hostname, '.')))
      *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    0x2e2b(%rip),%rax
mov    (%rax),%eax
add    $0x1,%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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <setprogname@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdf6(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     125d <main+0xbd>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x3f,%eax
je     124c <main+0xac>
jmp    122f <main+0x8f>
mov    -0x44(%rbp),%eax
sub    $0x73,%eax
jne    1251 <main+0xb1>
jmp    1240 <main+0xa0>
movl   $0x1,-0x18(%rbp)
jmp    1258 <main+0xb8>
jmp    1251 <main+0xb1>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11fc <main+0x5c>
mov    0x2d7c(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1298 <main+0xf8>
mov    $0x0,%al
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e8 <main+0x148>
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     12e3 <main+0x143>
mov    $0x1,%edi
lea    0xd24(%rip),%rsi
call   1070 <err@plt>
jmp    135f <main+0x1bf>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
call   10a0 <gethostname@plt>
cmp    $0x0,%rax
je     1312 <main+0x172>
mov    $0x1,%edi
lea    0xd01(%rip),%rsi
call   1070 <err@plt>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x18(%rbp)
je     134f <main+0x1af>
mov    -0x38(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     134f <main+0x1af>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rsi
lea    0xcc0(%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    0x2e2e(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%r15
mov    %rax,-0x30(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    (%rsi),%rdi
call   10c0 <setprogname@plt>
mov    $0x1,%r14b
lea    0xe1a(%rip),%r13
jmp    11f0 <main+0x50>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
cmp    $0x73,%eax
je     11e8 <main+0x48>
cmp    $0xffffffff,%eax
je     1210 <main+0x70>
xor    %eax,%eax
call   1080 <usage@plt>
jmp    11f0 <main+0x50>
mov    0x2dc9(%rip),%rax
mov    (%rax),%r13
sub    %r13d,%ebx
cmp    $0x2,%ebx
jl     1229 <main+0x89>
xor    %eax,%eax
call   1080 <usage@plt>
mov    (%r12,%r13,8),%rbx
test   %rbx,%rbx
jne    1288 <main+0xe8>
mov    %r15,%rdi
mov    -0x30(%rbp),%rbx
mov    %ebx,%esi
call   10a0 <gethostname@plt>
test   %rax,%rax
je     1256 <main+0xb6>
lea    0xdc2(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
movb   $0x0,-0x1(%rbx,%r15,1)
test   $0x1,%r14b
jne    1277 <main+0xd7>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1277 <main+0xd7>
movb   $0x0,(%rax)
lea    0xd9c(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
jmp    129f <main+0xff>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <sethostname@plt>
test   %rax,%rax
jne    12a6 <main+0x106>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd55(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

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

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