#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__ _check_ender(char const *, char const *, char const *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ substr(char const *, char **, int /*<<< orphan*/, int);
int _inner_expand(const char *c, char **result, const char *tld,
                  const char *domain) {
  if (_check_ender(c, tld, domain) > 0) {
    char *subdomain = NULL;
    substr(c, &subdomain, 0, (strlen(c) - strlen(tld)));
    *result = malloc(sizeof(char) * strlen(subdomain) + strlen(domain));
    strcpy(*result, subdomain);
    strcat(*result, domain);
    free(subdomain);
    return 1;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<_inner_expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <_check_ender@plt>
cmp    $0x0,%rax
jle    124a <_inner_expand+0xda>
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%rdi
sub    %eax,%ecx
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1070 <substr@plt>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1251 <_inner_expand+0xe1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_inner_expand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1040 <_check_ender@plt>
test   %rax,%rax
jle    120f <_inner_expand+0x9f>
movq   $0x0,0x8(%rsp)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
sub    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <substr@plt>
mov    0x8(%rsp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
mov    (%r14),%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    1214 <_inner_expand+0xa4>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_inner_expand(i8* %0, i8** %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %6
%12 = load i8*, i8** %8
%13 = load i8*, i8** %9
%14 = call i64 @_check_ender(i8* %11, i8* %12, i8* %13)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %45
16: ; preds = %4
store i8* null, i8** %10
%17 = load i8*, i8** %6
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %8
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %19, %21
%23 = call i32 @substr(i8* %17, i8** %10, i32 0, i32 %22)
%24 = load i8*, i8** %10
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = load i8*, i8** %9
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = add i64 %27, %30
%32 = trunc i64 %31 to i32
%33 = call i8* @malloc(i32 %32)
%34 = load i8**, i8*** %7
store i8* %33, i8** %34
%35 = load i8**, i8*** %7
%36 = load i8*, i8** %35
%37 = load i8*, i8** %10
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = load i8**, i8*** %7
%40 = load i8*, i8** %39
%41 = load i8*, i8** %9
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = load i8*, i8** %10
%44 = call i32 @free(i8* %43)
store i32 1, i32* %5
br label %46
45: ; preds = %4
store i32 -1, i32* %5
br label %46
46: ; preds = %45, %16
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
define i32 @_inner_expand(i8* %0, i8** nocapture %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = tail call i64 @_check_ender(i8* %0, i8* %2, i8* %3)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %4
%9 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%10 = tail call i32 @strlen(i8* %0)
%11 = tail call i32 @strlen(i8* %2)
%12 = sub nsw i32 %10, %11
%13 = call i32 @substr(i8* %0, i8** %5, i32 0, i32 %12)
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @strlen(i8* %3)
%17 = add i32 %16, %15
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %1
%19 = load i8*, i8** %5
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = load i8*, i8** %1
%22 = call i32 @strcat(i8* %21, i8* %3)
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %4, %8
%26 = phi i32 [ 1, %8 ], [ -1, %4 ]
ret i32 %26
}