#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*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *strchr(char *, char);
char *netmkaddr(char *linear, char *defnet, char *defsrv) {
  static char addr[512];
  char *cp;
  cp = strchr(linear, '!');
  if (cp == 0) {
    if (defnet == 0) {
      if (defsrv)
        snprintf(addr, sizeof addr, "net!%s!%s", linear, defsrv);
      else
        snprintf(addr, sizeof addr, "net!%s", linear);
    } else {
      if (defsrv)
        snprintf(addr, sizeof addr, "%s!%s!%s", defnet, linear, defsrv);
      else
        snprintf(addr, sizeof addr, "%s!%s", defnet, linear);
    }
    return addr;
  }
  cp = strchr(cp + 1, '!');
  if (cp)
    return linear;
  if (defsrv == 0)
    return linear;
  sprintf(addr, "%s!%s", linear, defsrv);
  return addr;
}


x86 assembly (clang, -O0):
<netmkaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x21,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122e <netmkaddr+0xfe>
cmpq   $0x0,-0x18(%rbp)
jne    11c1 <netmkaddr+0x91>
cmpq   $0x0,-0x20(%rbp)
je     119e <netmkaddr+0x6e>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0x2eca(%rip),%rdi
mov    $0x200,%esi
lea    0xe6e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11bc <netmkaddr+0x8c>
mov    -0x10(%rbp),%rcx
lea    0x2ea7(%rip),%rdi
mov    $0x200,%esi
lea    0xe55(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    121e <netmkaddr+0xee>
cmpq   $0x0,-0x20(%rbp)
je     11f7 <netmkaddr+0xc7>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0x2e71(%rip),%rdi
mov    $0x200,%esi
lea    0xe26(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1219 <netmkaddr+0xe9>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0x2e4a(%rip),%rdi
mov    $0x200,%esi
lea    0xe02(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    121e <netmkaddr+0xee>
lea    0x2e2b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    129a <netmkaddr+0x16a>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0x21,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     125c <netmkaddr+0x12c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    129a <netmkaddr+0x16a>
cmpq   $0x0,-0x20(%rbp)
jne    1274 <netmkaddr+0x144>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    129a <netmkaddr+0x16a>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0x2dcd(%rip),%rdi
lea    0xd8a(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x2dba(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netmkaddr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x21,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     118d <netmkaddr+0x5d>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x21,%esi
call   1030 <strchr@plt>
test   %r14,%r14
je     11ed <netmkaddr+0xbd>
test   %rax,%rax
jne    11ed <netmkaddr+0xbd>
lea    0x2eda(%rip),%r15
lea    0xe97(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <sprintf@plt>
jmp    11ea <netmkaddr+0xba>
test   %r15,%r15
je     11c2 <netmkaddr+0x92>
test   %r14,%r14
je     11fc <netmkaddr+0xcc>
lea    0x2eb2(%rip),%r12
lea    0xe6c(%rip),%rdx
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r15,%rcx
mov    %rbx,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r12,%rbx
jmp    11ed <netmkaddr+0xbd>
test   %r14,%r14
je     1224 <netmkaddr+0xf4>
lea    0x2e82(%rip),%r15
lea    0xe2b(%rip),%rdx
mov    %r15,%rdi
mov    $0x200,%esi
mov    %rbx,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x2e4d(%rip),%r14
lea    0xe0a(%rip),%rdx
mov    %r14,%rdi
mov    $0x200,%esi
mov    %r15,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r14,%rbx
jmp    11ed <netmkaddr+0xbd>
lea    0x2e25(%rip),%r14
lea    0xdd8(%rip),%rdx
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r14,%rbx
jmp    11ed <netmkaddr+0xbd>

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

LLVM IR (-O2):
@netmkaddr.addr = internal global [512 x i8] zeroinitializer
@.str = [10 x i8] c"net!%s!%s\00"
@.str.1 = [7 x i8] c"net!%s\00"
@.str.2 = [9 x i8] c"%s!%s!%s\00"
@.str.3 = [6 x i8] c"%s!%s\00"
define i8* @netmkaddr(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 33)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = icmp eq i8* %1, null
%8 = icmp eq i8* %2, null
br i1 %7, label %9, label %14
9: ; preds = %6
br i1 %8, label %12, label %10
10: ; preds = %9
%11 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %2)
br label %27
12: ; preds = %9
%13 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
14: ; preds = %6
br i1 %8, label %17, label %15
15: ; preds = %14
%16 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %0, i8* %2)
br label %27
17: ; preds = %14
%18 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
br label %27
19: ; preds = %3
%20 = getelementptr inbounds i8, i8* %4, i64 1
%21 = tail call i8* @strchr(i8* %20, i8 signext 33)
%22 = icmp ne i8* %21, null
%23 = icmp eq i8* %2, null
%24 = or i1 %23, %22
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %2)
br label %27
27: ; preds = %19, %12, %10, %17, %15, %25
%28 = phi i8* [ getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), %25 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), %15 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), %17 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), %10 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @netmkaddr.addr, i64 0, i64 0), %12 ], [ %0, %19 ]
ret i8* %28
}