#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*/ free(char *);
char *parse_sub_domain(char const *, char **);
char *strdupcat(char *, char *);
const char *parse_domain(const char *domain, char **pbuf) {
  char *buf;
  const char *ret = parse_sub_domain(domain, &buf);
  const char *ret_save;
  if (!ret)
    return NULL;
  ret_save = ret;
  while (*ret++ == '.') {
    char *new_sub_domain;
    if ((ret = parse_sub_domain(ret, &new_sub_domain))) {
      char *new_buf = strdupcat(buf, ".");
      free(buf);
      if (!new_buf) {
        free(new_sub_domain);
        return NULL;
      }
      buf = strdupcat(new_buf, new_sub_domain);
      free(new_sub_domain);
      free(new_buf);
      if (!buf)
        return NULL;
      ret_save = ret;
    } else
      break;
  }
  *pbuf = buf;
  return ret_save;
}


x86 assembly (clang, -O0):
<parse_domain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <parse_sub_domain@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1169 <parse_domain+0x39>
movq   $0x0,-0x8(%rbp)
jmp    124a <parse_domain+0x11a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1237 <parse_domain+0x107>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <parse_sub_domain@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     122d <parse_domain+0xfd>
mov    -0x20(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1050 <strdupcat@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
jne    11e5 <parse_domain+0xb5>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    124a <parse_domain+0x11a>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <strdupcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1220 <parse_domain+0xf0>
movq   $0x0,-0x8(%rbp)
jmp    124a <parse_domain+0x11a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1232 <parse_domain+0x102>
jmp    1237 <parse_domain+0x107>
jmp    1171 <parse_domain+0x41>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_domain>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rsp,%rsi
call   1040 <parse_sub_domain@plt>
test   %rax,%rax
je     11eb <parse_domain+0xbb>
mov    %rax,%rbx
cmpb   $0x2e,(%rax)
jne    11d7 <parse_domain+0xa7>
lea    0x8(%rsp),%r15
lea    0xe97(%rip),%r12
nopl   0x0(%rax)
lea    0x1(%rbx),%rdi
mov    %r15,%rsi
call   1040 <parse_sub_domain@plt>
test   %rax,%rax
je     11d7 <parse_domain+0xa7>
mov    %rax,%r13
mov    (%rsp),%rdi
mov    %r12,%rsi
call   1050 <strdupcat@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rsi
test   %rbx,%rbx
je     11e3 <parse_domain+0xb3>
mov    %rbx,%rdi
call   1050 <strdupcat@plt>
mov    %rax,(%rsp)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
cmpq   $0x0,(%rsp)
je     11eb <parse_domain+0xbb>
cmpb   $0x2e,0x0(%r13)
mov    %r13,%rbx
je     1170 <parse_domain+0x40>
jmp    11da <parse_domain+0xaa>
mov    %rbx,%r13
mov    (%rsp),%rax
mov    %rax,(%r14)
jmp    11ee <parse_domain+0xbe>
mov    %rsi,%rdi
call   1030 <free@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @parse_domain(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%11 = load i8*, i8** %4
%12 = call i8* @parse_sub_domain(i8* %11, i8** %6)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i8* null, i8** %3
br label %57
16: ; preds = %2
%17 = load i8*, i8** %7
store i8* %17, i8** %8
br label %18
18: ; preds = %52, %16
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %7
%21 = load i8, i8* %19
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 46
br i1 %23, label %24, label %53
24: ; preds = %18
%25 = load i8*, i8** %7
%26 = call i8* @parse_sub_domain(i8* %25, i8** %9)
store i8* %26, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %51
28: ; preds = %24
%29 = load i8*, i8** %6
%30 = call i8* @strdupcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %30, i8** %10
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %10
%34 = icmp ne i8* %33, null
br i1 %34, label %38, label %35
35: ; preds = %28
%36 = load i8*, i8** %9
%37 = call i32 @free(i8* %36)
store i8* null, i8** %3
br label %57
38: ; preds = %28
%39 = load i8*, i8** %10
%40 = load i8*, i8** %9
%41 = call i8* @strdupcat(i8* %39, i8* %40)
store i8* %41, i8** %6
%42 = load i8*, i8** %9
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %10
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %6
%47 = icmp ne i8* %46, null
br i1 %47, label %49, label %48
48: ; preds = %38
store i8* null, i8** %3
br label %57
49: ; preds = %38
%50 = load i8*, i8** %7
store i8* %50, i8** %8
br label %52
51: ; preds = %24
br label %53
52: ; preds = %49
br label %18
53: ; preds = %51, %18
%54 = load i8*, i8** %6
%55 = load i8**, i8*** %5
store i8* %54, i8** %55
%56 = load i8*, i8** %8
store i8* %56, i8** %3
br label %57
57: ; preds = %53, %48, %35, %15
%58 = load i8*, i8** %3
ret i8* %58
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @parse_domain(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = call i8* @parse_sub_domain(i8* %0, i8** %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %42, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 46
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = bitcast i8** %4 to i8*
br label %13
13: ; preds = %11, %36
%14 = phi i8* [ %6, %11 ], [ %16, %36 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i8* @parse_sub_domain(i8* %15, i8** %4)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
br label %39
19: ; preds = %13
%20 = load i8*, i8** %3
%21 = call i8* @strdupcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
%24 = icmp eq i8* %21, null
%25 = load i8*, i8** %4
br i1 %24, label %26, label %28
26: ; preds = %19
%27 = call i32 @free(i8* %25)
br label %35
28: ; preds = %19
%29 = call i8* @strdupcat(i8* %21, i8* %25)
store i8* %29, i8** %3
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
%32 = call i32 @free(i8* %21)
%33 = load i8*, i8** %3
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %28, %26
br label %42
36: ; preds = %28
%37 = load i8, i8* %16
%38 = icmp eq i8 %37, 46
br i1 %38, label %13, label %39
39: ; preds = %36, %8, %18
%40 = phi i8* [ %14, %18 ], [ %6, %8 ], [ %16, %36 ]
%41 = load i8*, i8** %3
store i8* %41, i8** %1
br label %42
42: ; preds = %35, %2, %39
%43 = phi i8* [ %40, %39 ], [ null, %2 ], [ null, %35 ]
ret i8* %43
}