#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*/ tmp_str;
typedef int /*<<< orphan*/ prompt;

/* Variables and functions */
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void ion_set_prompt(char *prompt) {
  char tmp_str[128];
  int c = 0;
  if (gethostname(tmp_str, sizeof(tmp_str))) {
    strcpy(prompt, "ion");
  } else {
    while (c < sizeof(tmp_str)) {
      if (tmp_str[c] == '.') {
        prompt[c] = '\0';
        break;
      }
      prompt[c] = tmp_str[c];
      c++;
    }
  }
  strncat(prompt, "> ", sizeof(prompt));
}


x86 assembly (clang, -O0):
<ion_set_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1050 <gethostname@plt>
cmp    $0x0,%rax
je     1179 <ion_set_prompt+0x49>
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f2 <ion_set_prompt+0xc2>
jmp    117e <ion_set_prompt+0x4e>
movslq -0x94(%rbp),%rax
cmp    $0x80,%rax
jae    11ed <ion_set_prompt+0xbd>
movslq -0x94(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0x2e,%eax
jne    11bd <ion_set_prompt+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x94(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ed <ion_set_prompt+0xbd>
movslq -0x94(%rbp),%rax
mov    -0x90(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    117e <ion_set_prompt+0x4e>
jmp    11f2 <ion_set_prompt+0xc2>
mov    -0x8(%rbp),%rdi
lea    0xe07(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncat@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ion_set_prompt>:
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x80,%esi
call   1050 <gethostname@plt>
test   %rax,%rax
je     115e <ion_set_prompt+0x2e>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    11ba <ion_set_prompt+0x8a>
xor    %eax,%eax
movzbl (%rsp,%rax,1),%ecx
cmp    $0x2e,%cl
je     11b4 <ion_set_prompt+0x84>
mov    %cl,(%rbx,%rax,1)
movzbl 0x1(%rsp,%rax,1),%ecx
cmp    $0x2e,%cl
je     11a4 <ion_set_prompt+0x74>
mov    %cl,0x1(%rbx,%rax,1)
movzbl 0x2(%rsp,%rax,1),%ecx
cmp    $0x2e,%cl
je     11aa <ion_set_prompt+0x7a>
mov    %cl,0x2(%rbx,%rax,1)
movzbl 0x3(%rsp,%rax,1),%ecx
cmp    $0x2e,%cl
je     11b0 <ion_set_prompt+0x80>
mov    %cl,0x3(%rbx,%rax,1)
add    $0x4,%rax
cmp    $0x80,%rax
jne    1160 <ion_set_prompt+0x30>
jmp    11ba <ion_set_prompt+0x8a>
add    $0x1,%rax
jmp    11b4 <ion_set_prompt+0x84>
add    $0x2,%rax
jmp    11b4 <ion_set_prompt+0x84>
add    $0x3,%rax
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
lea    0xe43(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <strncat@plt>
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ion\00"
@.str.1 = [3 x i8] c"> \00"
define void @ion_set_prompt(i8* %0) {
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = call i64 @gethostname(i8* %5, i32 128)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %40
11: ; preds = %1
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %14, 128
br i1 %15, label %16, label %39
16: ; preds = %12
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 46
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
br label %39
28: ; preds = %16
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %2
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %12
39: ; preds = %23, %12
br label %40
40: ; preds = %39, %8
%41 = load i8*, i8** %2
%42 = call i32 @strncat(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 8)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"ion\00"
@.str.1 = [3 x i8] c"> \00"
define void @ion_set_prompt(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i64 @gethostname(i8* %3, i32 128)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %39
8: ; preds = %1, %35
%9 = phi i64 [ %37, %35 ], [ 0, %1 ]
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 46
br i1 %12, label %13, label %17
13: ; preds = %29, %23, %17, %8
%14 = phi i64 [ %9, %8 ], [ %19, %17 ], [ %25, %23 ], [ %31, %29 ]
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
br label %39
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %11, i8* %18
%19 = or i64 %9, 1
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 46
br i1 %22, label %13, label %23
23: ; preds = %17
%24 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 %21, i8* %24
%25 = or i64 %9, 2
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 46
br i1 %28, label %13, label %29
29: ; preds = %23
%30 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %27, i8* %30
%31 = or i64 %9, 3
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 46
br i1 %34, label %13, label %35
35: ; preds = %29
%36 = getelementptr inbounds i8, i8* %0, i64 %31
store i8 %33, i8* %36
%37 = add nuw nsw i64 %9, 4
%38 = icmp eq i64 %37, 128
br i1 %38, label %39, label %8
39: ; preds = %35, %13, %6
%40 = call i32 @strncat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 8)
ret void
}