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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ sethostname(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char **argv) {
  int i, j, len, retval = 0;
  char *n;
  if (argc != 2)
    return 1;
  n = argv[1];
  len = strlen(n);
  for (i = 0, j = 0; i < len; i++)
    if (n[i] >= ' ')
      n[j++] = n[i];
  n[j] = 0;
  if (sethostname(n, j)) {
    fprintf(stderr, "Failed to set hostname to '%s': %s\n", n, strerror(errno));
    retval = 1;
  } else {
    FILE *f;
    printf("Host name set to '%s'\n", n);
    if (!(f = fopen("/etc/hostname", "w"))) {
      fprintf(stderr, "Failed to set save hostname: %s\n", strerror(errno));
      retval = 2;
    } else {
      if (fwrite(n, j, 1, f) != 1) {
        fprintf(stderr, "Failed to set save hostname: %s\n", strerror(errno));
        retval = 2;
      }
      fclose(f);
    }
  }
  return retval;
}


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)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b3 <main+0x33>
movl   $0x1,-0x4(%rbp)
jmp    1367 <main+0x1e7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    122d <main+0xad>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     121a <main+0x9a>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    121f <main+0x9f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d9 <main+0x59>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1070 <sethostname@plt>
cmp    $0x0,%rax
je     1295 <main+0x115>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x20(%rbp)
jmp    1361 <main+0x1e1>
mov    -0x28(%rbp),%rsi
lea    0xd84(%rip),%rdi
call   1050 <printf@plt>
lea    0xd8f(%rip),%rdi
lea    0xd96(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1300 <main+0x180>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xd5e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x20(%rbp)
jmp    135c <main+0x1dc>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     1353 <main+0x1d3>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xd06(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1361 <main+0x1e1>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%r14d
cmp    $0x2,%edi
jne    1314 <main+0x194>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11cd <main+0x4d>
mov    %eax,%esi
cmp    $0x1,%eax
jne    1297 <main+0x117>
xor    %eax,%eax
xor    %ebp,%ebp
test   $0x1,%sil
je     11cf <main+0x4f>
mov    (%rbx,%rax,1),%al
cmp    $0x20,%al
jl     11cf <main+0x4f>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%rbx,%rcx,1)
jmp    11cf <main+0x4f>
xor    %ebp,%ebp
movslq %ebp,%rsi
movb   $0x0,(%rbx,%rsi,1)
mov    %rbx,%rdi
call   1070 <sethostname@plt>
test   %rax,%rax
je     1215 <main+0x95>
mov    0x2df6(%rip),%rax
mov    (%rax),%ebp
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdff(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1314 <main+0x194>
lea    0xe08(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe10(%rip),%rdi
lea    0xe17(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e4 <main+0x164>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
xor    %r14d,%r14d
cmp    $0x1,%eax
je     128d <main+0x10d>
mov    0x2d7c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdd0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%r14d
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    1314 <main+0x194>
mov    %esi,%edx
and    $0xfffffffe,%edx
xor    %eax,%eax
xor    %ebp,%ebp
jmp    12bd <main+0x13d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x2,%rax
cmp    %rax,%rdx
je     11b5 <main+0x35>
movzbl (%rbx,%rax,1),%ecx
cmp    $0x20,%cl
jl     12cf <main+0x14f>
movslq %ebp,%rdi
add    $0x1,%ebp
mov    %cl,(%rbx,%rdi,1)
movzbl 0x1(%rbx,%rax,1),%ecx
cmp    $0x20,%cl
jl     12b0 <main+0x130>
movslq %ebp,%rdi
add    $0x1,%ebp
mov    %cl,(%rbx,%rdi,1)
jmp    12b0 <main+0x130>
mov    0x2cf5(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd49(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Failed to set hostname to '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"Host name set to '%s'\0A\00"
@.str.2 = [14 x i8] c"/etc/hostname\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [33 x i8] c"Failed to set save hostname: %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 i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %90
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %8
store i32 0, i32* %6
store i32 0, i32* %7
br label %21
21: ; preds = %45, %15
%22 = load i32, i32* %6
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %48
25: ; preds = %21
%26 = load i8*, i8** %10
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp sge i32 %31, 32
br i1 %32, label %33, label %44
33: ; preds = %25
%34 = load i8*, i8** %10
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %10
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 %38, i8* %43
br label %44
44: ; preds = %33, %25
br label %45
45: ; preds = %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %21
48: ; preds = %21
%49 = load i8*, i8** %10
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
%53 = load i8*, i8** %10
%54 = load i32, i32* %7
%55 = call i64 @sethostname(i8* %53, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %48
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %10
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %59, i8* %61)
store i32 1, i32* %9
br label %88
63: ; preds = %48
%64 = load i8*, i8** %10
%65 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %64)
%66 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %66, i32** %11
%67 = icmp ne i32* %66, null
br i1 %67, label %73, label %68
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %71)
store i32 2, i32* %9
br label %87
73: ; preds = %63
%74 = load i8*, i8** %10
%75 = load i32, i32* %7
%76 = load i32*, i32** %11
%77 = call i32 @fwrite(i8* %74, i32 %75, i32 1, i32* %76)
%78 = icmp ne i32 %77, 1
br i1 %78, label %79, label %84
79: ; preds = %73
%80 = load i32, i32* @stderr
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %82)
store i32 2, i32* %9
br label %84
84: ; preds = %79, %73
%85 = load i32*, i32** %11
%86 = call i32 @fclose(i32* %85)
br label %87
87: ; preds = %84, %68
br label %88
88: ; preds = %87, %57
%89 = load i32, i32* %9
store i32 %89, i32* %3
br label %90
90: ; preds = %88, %14
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Failed to set hostname to '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"Host name set to '%s'\0A\00"
@.str.2 = [14 x i8] c"/etc/hostname\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [33 x i8] c"Failed to set save hostname: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %85
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strlen(i8* %6)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %54
9: ; preds = %4
%10 = zext i32 %7 to i64
%11 = and i64 %10, 1
%12 = icmp eq i32 %7, 1
br i1 %12, label %41, label %13
13: ; preds = %9
%14 = and i64 %10, 4294967294
br label %15
15: ; preds = %36, %13
%16 = phi i64 [ 0, %13 ], [ %38, %36 ]
%17 = phi i32 [ 0, %13 ], [ %37, %36 ]
%18 = phi i64 [ 0, %13 ], [ %39, %36 ]
%19 = getelementptr inbounds i8, i8* %6, i64 %16
%20 = load i8, i8* %19
%21 = icmp sgt i8 %20, 31
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = add nsw i32 %17, 1
%24 = sext i32 %17 to i64
%25 = getelementptr inbounds i8, i8* %6, i64 %24
store i8 %20, i8* %25
br label %26
26: ; preds = %15, %22
%27 = phi i32 [ %23, %22 ], [ %17, %15 ]
%28 = or i64 %16, 1
%29 = getelementptr inbounds i8, i8* %6, i64 %28
%30 = load i8, i8* %29
%31 = icmp sgt i8 %30, 31
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = add nsw i32 %27, 1
%34 = sext i32 %27 to i64
%35 = getelementptr inbounds i8, i8* %6, i64 %34
store i8 %30, i8* %35
br label %36
36: ; preds = %32, %26
%37 = phi i32 [ %33, %32 ], [ %27, %26 ]
%38 = add nuw nsw i64 %16, 2
%39 = add i64 %18, 2
%40 = icmp eq i64 %39, %14
br i1 %40, label %41, label %15
41: ; preds = %36, %9
%42 = phi i32 [ undef, %9 ], [ %37, %36 ]
%43 = phi i64 [ 0, %9 ], [ %38, %36 ]
%44 = phi i32 [ 0, %9 ], [ %37, %36 ]
%45 = icmp eq i64 %11, 0
br i1 %45, label %54, label %46
46: ; preds = %41
%47 = getelementptr inbounds i8, i8* %6, i64 %43
%48 = load i8, i8* %47
%49 = icmp sgt i8 %48, 31
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = add nsw i32 %44, 1
%52 = sext i32 %44 to i64
%53 = getelementptr inbounds i8, i8* %6, i64 %52
store i8 %48, i8* %53
br label %54
54: ; preds = %41, %50, %46, %4
%55 = phi i32 [ 0, %4 ], [ %42, %41 ], [ %51, %50 ], [ %44, %46 ]
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %6, i64 %56
store i8 0, i8* %57
%58 = tail call i64 @sethostname(i8* %6, i32 %55)
%59 = icmp eq i64 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %54
%61 = load i32, i32* @stderr
%62 = load i32, i32* @errno
%63 = tail call i8* @strerror(i32 %62)
%64 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %63)
br label %85
65: ; preds = %54
%66 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%67 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %74
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = load i32, i32* @errno
%72 = tail call i8* @strerror(i32 %71)
%73 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %72)
br label %85
74: ; preds = %65
%75 = tail call i32 @fwrite(i8* %6, i32 %55, i32 1, i32* %67)
%76 = icmp eq i32 %75, 1
br i1 %76, label %82, label %77
77: ; preds = %74
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = tail call i8* @strerror(i32 %79)
%81 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %77, %74
%83 = phi i32 [ 2, %77 ], [ 0, %74 ]
%84 = tail call i32 @fclose(i32* %67)
br label %85
85: ; preds = %60, %82, %69, %2
%86 = phi i32 [ 1, %2 ], [ 1, %60 ], [ %83, %82 ], [ 2, %69 ]
ret i32 %86
}