#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*/ serverbuff;
typedef int /*<<< orphan*/ adrstr;

/* Variables and functions */
scalar_t__ Q_stricmp(char *, char *);
int /*<<< orphan*/ trap_Cvar_Set(char *, char *);
int /*<<< orphan*/ trap_Cvar_VariableStringBuffer(char *, char *, int);
char *va(char *, int);
void Favorites_Add(void) {
  char adrstr[128];
  char serverbuff[128];
  int i;
  int best;
  trap_Cvar_VariableStringBuffer("cl_currentServerAddress", serverbuff,
                                 sizeof(serverbuff));
  if (!serverbuff[0]) {
    return;
  }
  best = 0;
  for (i = 0; i < 16; i++) {
    trap_Cvar_VariableStringBuffer(va("server%d", i + 1), adrstr,
                                   sizeof(adrstr));
    if ((Q_stricmp(serverbuff, adrstr) == 0)) {
      return;
    }
    if ((adrstr[0] < '0' || adrstr[0] > '9') && !best) {
      best = i + 1;
    }
  }
  if (best) {
    trap_Cvar_Set(va("server%d", best), serverbuff);
  }
}


x86 assembly (clang, -O0):
<Favorites_Add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rsi
lea    0xea7(%rip),%rdi
mov    $0x80,%edx
call   1040 <trap_Cvar_VariableStringBuffer@plt>
cmpb   $0x0,-0x100(%rbp)
jne    1175 <Favorites_Add+0x35>
jmp    1258 <Favorites_Add+0x118>
movl   $0x0,-0x108(%rbp)
movl   $0x0,-0x104(%rbp)
cmpl   $0x10,-0x104(%rbp)
jge    122a <Favorites_Add+0xea>
mov    -0x104(%rbp),%esi
add    $0x1,%esi
lea    0xe72(%rip),%rdi
call   1050 <va@plt>
mov    %rax,%rdi
lea    -0x80(%rbp),%rsi
mov    $0x80,%edx
call   1040 <trap_Cvar_VariableStringBuffer@plt>
lea    -0x100(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <Q_stricmp@plt>
cmp    $0x0,%rax
jne    11db <Favorites_Add+0x9b>
jmp    1258 <Favorites_Add+0x118>
movsbl -0x80(%rbp),%eax
cmp    $0x30,%eax
jl     11f5 <Favorites_Add+0xb5>
movsbl -0x80(%rbp),%eax
cmp    $0x39,%eax
jle    1211 <Favorites_Add+0xd1>
cmpl   $0x0,-0x108(%rbp)
jne    1211 <Favorites_Add+0xd1>
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x108(%rbp)
jmp    1216 <Favorites_Add+0xd6>
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x104(%rbp)
jmp    1189 <Favorites_Add+0x49>
cmpl   $0x0,-0x108(%rbp)
je     1258 <Favorites_Add+0x118>
mov    -0x108(%rbp),%esi
lea    0xdd4(%rip),%rdi
call   1050 <va@plt>
mov    %rax,%rdi
lea    -0x100(%rbp),%rsi
call   1060 <trap_Cvar_Set@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Favorites_Add>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
lea    0xeaa(%rip),%rdi
mov    %rsp,%rsi
mov    $0x80,%edx
call   1040 <trap_Cvar_VariableStringBuffer@plt>
cmpb   $0x0,(%rsp)
je     11f5 <Favorites_Add+0xb5>
xor    %ebx,%ebx
mov    $0x1,%ebp
lea    0xe9d(%rip),%r14
lea    0x80(%rsp),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <va@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x80,%edx
call   1040 <trap_Cvar_VariableStringBuffer@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <Q_stricmp@plt>
test   %rax,%rax
je     11f5 <Favorites_Add+0xb5>
movzbl 0x80(%rsp),%eax
add    $0xd0,%al
test   %ebx,%ebx
mov    %ebp,%ecx
cmovne %ebx,%ecx
cmp    $0xa,%al
cmovae %ecx,%ebx
add    $0x1,%ebp
cmp    $0x11,%ebp
jne    1190 <Favorites_Add+0x50>
test   %ebx,%ebx
je     11f5 <Favorites_Add+0xb5>
lea    0xe35(%rip),%rdi
mov    %ebx,%esi
call   1050 <va@plt>
mov    %rsp,%rsi
mov    %rax,%rdi
call   1060 <trap_Cvar_Set@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"cl_currentServerAddress\00"
@.str.1 = [9 x i8] c"server%d\00"
define void @Favorites_Add() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i32 @trap_Cvar_VariableStringBuffer(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %4, i32 128)
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %29, label %8
8: ; preds = %0, %16
%9 = phi i32 [ %22, %16 ], [ 0, %0 ]
%10 = phi i32 [ %11, %16 ], [ 0, %0 ]
%11 = add nuw nsw i32 %10, 1
%12 = call i8* @va(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @trap_Cvar_VariableStringBuffer(i8* %12, i8* %3, i32 128)
%14 = call i64 @Q_stricmp(i8* %4, i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %29, label %16
16: ; preds = %8
%17 = load i8, i8* %3
%18 = add i8 %17, -48
%19 = icmp ult i8 %18, 10
%20 = icmp ne i32 %9, 0
%21 = select i1 %19, i1 true, i1 %20
%22 = select i1 %21, i32 %9, i32 %11
%23 = icmp eq i32 %11, 16
br i1 %23, label %24, label %8
24: ; preds = %16
%25 = icmp eq i32 %22, 0
br i1 %25, label %29, label %26
26: ; preds = %24
%27 = call i8* @va(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%28 = call i32 @trap_Cvar_Set(i8* %27, i8* %4)
br label %29
29: ; preds = %8, %24, %26, %0
ret void
}