#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 */
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ strcasecmp(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void trimdomain(char *cp) {
  static char domain[64 + 1];
  static int first = 1;
  char *s;
  if (first) {
    first = 0;
    if (gethostname(domain, 64) == 0 && (s = strchr(domain, '.')))
      (void)strcpy(domain, s + 1);
    else
      domain[0] = 0;
  }
  if (domain[0]) {
    while ((cp = strchr(cp, '.'))) {
      if (!strcasecmp(cp + 1, domain)) {
        *cp = 0;
        break;
      } else {
        cp++;
      }
    }
  }
}


x86 assembly (clang, -O0):
<trimdomain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpl   $0x0,0x2eed(%rip)
je     11c2 <trimdomain+0x82>
movl   $0x0,0x2edd(%rip)
lea    0x2ef6(%rip),%rdi
mov    $0x40,%esi
call   1060 <gethostname@plt>
cmp    $0x0,%rax
jne    11b6 <trimdomain+0x76>
lea    0x2edb(%rip),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11b6 <trimdomain+0x76>
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
lea    0x2eb4(%rip),%rdi
call   1040 <strcpy@plt>
jmp    11bd <trimdomain+0x7d>
movb   $0x0,0x2ea3(%rip)
jmp    11c2 <trimdomain+0x82>
cmpb   $0x0,0x2e97(%rip)
je     122f <trimdomain+0xef>
jmp    11d4 <trimdomain+0x94>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     122a <trimdomain+0xea>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0x2e61(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1219 <trimdomain+0xd9>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    122a <trimdomain+0xea>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <trimdomain+0x94>
jmp    122f <trimdomain+0xef>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimdomain>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
cmpb   $0x0,0x2f45(%rip)
jne    11a0 <trimdomain+0x60>
movb   $0x1,0x2f3c(%rip)
lea    0x2ef1(%rip),%rdi
mov    $0x40,%esi
call   1060 <gethostname@plt>
test   %rax,%rax
je     1177 <trimdomain+0x37>
movb   $0x0,0x2edb(%rip)
jmp    11db <trimdomain+0x9b>
lea    0x2ed2(%rip),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     116e <trimdomain+0x2e>
add    $0x1,%rax
lea    0x2eb8(%rip),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,0x2ea9(%rip)
je     11db <trimdomain+0x9b>
lea    0x2ea0(%rip),%r14
mov    %r15,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11db <trimdomain+0x9b>
mov    %rax,%rbx
lea    0x1(%rax),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
jne    11b0 <trimdomain+0x70>
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@trimdomain.domain = internal global [65 x i8] zeroinitializer
@trimdomain.first = internal global i32 1
define void @trimdomain(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i32, i32* @trimdomain.first
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %1
store i32 0, i32* @trimdomain.first
%7 = call i64 @gethostname(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0), i32 64)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = call i8* @strchr(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0), i8 signext 46)
store i8* %10, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i32 @strcpy(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0), i8* %14)
br label %17
16: ; preds = %9, %6
store i8 0, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0)
br label %17
17: ; preds = %16, %12
br label %18
18: ; preds = %17, %1
%19 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0)
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %18
br label %22
22: ; preds = %36, %21
%23 = load i8*, i8** %2
%24 = call i8* @strchr(i8* %23, i8 signext 46)
store i8* %24, i8** %2
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @strcasecmp(i8* %28, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = load i8*, i8** %2
store i8 0, i8* %32
br label %37
33: ; preds = %26
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %2
br label %36
36: ; preds = %33
br label %22
37: ; preds = %31, %22
br label %38
38: ; preds = %37, %18
ret void
}

LLVM IR (-O2):
@trimdomain.domain = internal global [65 x i8] zeroinitializer
@trimdomain.first = internal unnamed_addr global i1 false
define void @trimdomain(i8* %0) {
%2 = load i1, i1* @trimdomain.first
br i1 %2, label %13, label %3
3: ; preds = %1
store i1 true, i1* @trimdomain.first
%4 = tail call i64 @gethostname(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0), i32 64)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0), i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = tail call i32 @strcpy(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0), i8* %10)
br label %13
12: ; preds = %3, %6
store i8 0, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0)
br label %25
13: ; preds = %9, %1
%14 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0)
%15 = icmp eq i8 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13, %20
%17 = phi i8* [ %21, %20 ], [ %0, %13 ]
%18 = tail call i8* @strchr(i8* dereferenceable(1) %17, i8 signext 46)
%19 = icmp eq i8* %18, null
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = tail call i32 @strcasecmp(i8* %21, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @trimdomain.domain, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %16
24: ; preds = %20
store i8 0, i8* %18
br label %25
25: ; preds = %16, %12, %24, %13
ret void
}