#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 gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_help();
int sethostname(char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc == 1) {
    char hostname[255 + 1];
    if (gethostname(hostname, 255) == -1) {
      perror("uname");
    }
    write(1, hostname, strlen(hostname));
    write(1, "\n", 1);
    return 0;
  }
  int i = 1;
  do {
    if (*argv[i] == '-') {
      ++argv[i];
      switch (*argv[i]) {
      case 's':
        if (i + 1 < argc) {
          ++i;
          if (sethostname(argv[i], strlen(argv[i])) == -1)
            perror("hostname");
        }
        break;
      case 'h':
        print_help();
        break;
      }
    }
    ++i;
  } while (i < argc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11f5 <main+0x95>
lea    -0x110(%rbp),%rdi
mov    $0xff,%esi
call   1080 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    11a9 <main+0x49>
lea    0xe5c(%rip),%rdi
call   1060 <perror@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x120(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    $0x1,%edx
lea    0xe24(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
jmp    1314 <main+0x1b4>
movl   $0x1,-0x114(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12ef <main+0x18f>
mov    -0x10(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x1,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
mov    %eax,-0x124(%rbp)
sub    $0x68,%eax
je     12e3 <main+0x183>
jmp    1257 <main+0xf7>
mov    -0x124(%rbp),%eax
sub    $0x73,%eax
jne    12ea <main+0x18a>
jmp    126b <main+0x10b>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    12de <main+0x17e>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x130(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%esi
call   1050 <sethostname@plt>
cmp    $0xffffffff,%eax
jne    12d9 <main+0x179>
lea    0xd34(%rip),%rdi
call   1060 <perror@plt>
jmp    12de <main+0x17e>
jmp    12ea <main+0x18a>
mov    $0x0,%al
call   1070 <print_help@plt>
jmp    12ef <main+0x18f>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11ff <main+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
cmp    $0x1,%edi
jne    11d0 <main+0x70>
mov    %rsp,%rdi
mov    $0xff,%esi
call   1080 <gethostname@plt>
cmp    $0xffffffff,%eax
je     1253 <main+0xf3>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe59(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rbx
mov    %edi,%r12d
mov    $0x1,%ebp
lea    0xe26(%rip),%r14
jmp    11f8 <main+0x98>
xor    %eax,%eax
call   1070 <print_help@plt>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r12d,%ebp
jge    11bc <main+0x5c>
movslq %ebp,%rax
mov    (%rbx,%rax,8),%rcx
cmpb   $0x2d,(%rcx)
jne    11f0 <main+0x90>
lea    0x1(%rcx),%rdx
mov    %rdx,(%rbx,%rax,8)
movsbl 0x1(%rcx),%eax
cmp    $0x68,%eax
je     11e4 <main+0x84>
cmp    $0x73,%eax
jne    11f0 <main+0x90>
lea    0x1(%rbp),%r13d
cmp    %r12d,%r13d
jge    11f0 <main+0x90>
movslq %r13d,%rax
mov    (%rbx,%rax,8),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <sethostname@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xe6>
mov    %r13d,%ebp
jmp    11f0 <main+0x90>
mov    %r14,%rdi
call   1060 <perror@plt>
mov    %r13d,%ebp
jmp    11f0 <main+0x90>
lea    0xda6(%rip),%rdi
call   1060 <perror@plt>
jmp    118c <main+0x2c>

LLVM IR (-O0):
@.str = [6 x i8] c"uname\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [9 x i8] c"hostname\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i32 @gethostname(i8* %11, i32 255)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 1, i8* %17, i32 %19)
%21 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 0, i32* %3
br label %82
22: ; preds = %2
store i32 1, i32* %7
br label %23
23: ; preds = %77, %22
%24 = load i8**, i8*** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 45
br i1 %31, label %32, label %74
32: ; preds = %23
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %36
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
switch i32 %45, label %73 [
i32 115, label %46
i32 104, label %71
]
46: ; preds = %32
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %70
51: ; preds = %46
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
%54 = load i8**, i8*** %5
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = load i8**, i8*** %5
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @strlen(i8* %63)
%65 = call i32 @sethostname(i8* %58, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %51
%68 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %69
69: ; preds = %67, %51
br label %70
70: ; preds = %69, %46
br label %73
71: ; preds = %32
%72 = call i32 (...) @print_help()
br label %73
73: ; preds = %32, %71, %70
br label %74
74: ; preds = %73, %23
%75 = load i32, i32* %7
%76 = add nsw i32 %75, 1
store i32 %76, i32* %7
br label %77
77: ; preds = %74
%78 = load i32, i32* %7
%79 = load i32, i32* %4
%80 = icmp slt i32 %78, %79
br i1 %80, label %23, label %81
81: ; preds = %77
store i32 0, i32* %3
br label %82
82: ; preds = %81, %16
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [6 x i8] c"uname\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [9 x i8] c"hostname\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = call i32 @gethostname(i8* %6, i32 255)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = call i32 @strlen(i8* %6)
%13 = call i32 @write(i32 1, i8* %6, i32 %12)
%14 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %44
15: ; preds = %2, %40
%16 = phi i32 [ %42, %40 ], [ 1, %2 ]
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 45
br i1 %21, label %22, label %40
22: ; preds = %15
%23 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %23, i8** %18
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
switch i32 %25, label %40 [
i32 115, label %26
i32 104, label %38
]
26: ; preds = %22
%27 = add nsw i32 %16, 1
%28 = icmp slt i32 %27, %0
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = sext i32 %27 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i32 @strlen(i8* %32)
%34 = tail call i32 @sethostname(i8* %32, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %40
38: ; preds = %22
%39 = tail call i32 (...) @print_help()
br label %40
40: ; preds = %38, %22, %29, %36, %26, %15
%41 = phi i32 [ %16, %22 ], [ %16, %38 ], [ %27, %36 ], [ %27, %29 ], [ %16, %26 ], [ %16, %15 ]
%42 = add nsw i32 %41, 1
%43 = icmp slt i32 %42, %0
br i1 %43, label %15, label %44
44: ; preds = %40, %11
ret i32 0
}