#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 /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sethostname(char *, int);
int strlen(char *);
void do_hostname(int argc, char **argv) {
  char hn[256 + 1];
  if (argc >= 2) {
    if (strlen(argv[1]) > 256) {
      printf("That name is too long.\n");
    } else {
      sethostname(argv[1], strlen(argv[1]));
    }
  } else {
    gethostname(hn, 256);
    printf("%s\n", hn);
  }
}


x86 assembly (clang, -O0):
<do_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jl     11b6 <do_hostname+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x100,%eax
jle    1187 <do_hostname+0x47>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b1 <do_hostname+0x71>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x128(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x128(%rbp),%rdi
mov    %eax,%esi
call   1050 <sethostname@plt>
jmp    11dc <do_hostname+0x9c>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1060 <gethostname@plt>
lea    -0x120(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_hostname>:
push   %rbx
sub    $0x110,%rsp
cmp    $0x2,%edi
jl     1174 <do_hostname+0x34>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <strlen@plt>
cmp    $0x101,%eax
jl     1195 <do_hostname+0x55>
lea    0xe99(%rip),%rdi
add    $0x110,%rsp
pop    %rbx
jmp    1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <gethostname@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x110,%rsp
pop    %rbx
ret
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x110,%rsp
pop    %rbx
jmp    1050 <sethostname@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"That name is too long.\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @do_hostname(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [257 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 2
br i1 %7, label %8, label %26
8: ; preds = %2
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %12, 256
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %25
16: ; preds = %8
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @sethostname(i8* %19, i32 %23)
br label %25
25: ; preds = %16, %14
br label %31
26: ; preds = %2
%27 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%28 = call i32 @gethostname(i8* %27, i32 256)
%29 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %26, %25
ret void
}

LLVM IR (-O2):
@str = [23 x i8] c"That name is too long.\00"
define void @do_hostname(i32 %0, i8** nocapture %1) {
%3 = alloca [257 x i8]
%4 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 256
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %20
13: ; preds = %6
%14 = load i8*, i8** %7
%15 = tail call i32 @strlen(i8* %14)
%16 = tail call i32 @sethostname(i8* %14, i32 %15)
br label %20
17: ; preds = %2
%18 = call i32 @gethostname(i8* %4, i32 256)
%19 = call i32 @puts(i8* %4)
br label %20
20: ; preds = %11, %13, %17
ret void
}