#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 */
struct qserver {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ *add_rule(struct qserver *, char *, char *, int);
int atoi(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
char *ut2003_strdup(char *, char *, char **);
int ut2003_rule_packet(struct qserver *server, char *rawpkt, char *end) {
  char *key, *value;
  int result = 0;
  rawpkt++;
  while (rawpkt < end) {
    if (NULL == (key = ut2003_strdup(rawpkt, end, &rawpkt))) {
      break;
    }
    if (NULL == (value = ut2003_strdup(rawpkt, end, &rawpkt))) {
      break;
    }
    if (strcmp(key, "minplayers") == 0) {
      result = atoi(value);
    }
    if (NULL == add_rule(server, key, value, 4 | 1 | 8)) {
      free(value);
      free(key);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1236 <ut2003_rule_packet+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <ut2003_strdup@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11ad <ut2003_rule_packet+0x5d>
jmp    1236 <ut2003_rule_packet+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <ut2003_strdup@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d5 <ut2003_rule_packet+0x85>
jmp    1236 <ut2003_rule_packet+0xe6>
mov    -0x20(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11fb <ut2003_rule_packet+0xab>
mov    -0x28(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0xd,%ecx
call   1050 <add_rule@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1231 <ut2003_rule_packet+0xe1>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
jmp    1177 <ut2003_rule_packet+0x27>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
add    $0x1,%rsi
mov    %rsi,(%rsp)
xor    %r15d,%r15d
cmp    %rdx,%rsi
jae    11ff <ut2003_rule_packet+0xaf>
mov    %rdx,%rbx
mov    %rdi,%r14
xor    %r15d,%r15d
mov    %rsp,%r13
jmp    1189 <ut2003_rule_packet+0x39>
nopl   (%rax)
mov    (%rsp),%rsi
cmp    %rbx,%rsi
jae    11ff <ut2003_rule_packet+0xaf>
mov    %rsi,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <ut2003_strdup@plt>
test   %rax,%rax
je     11ff <ut2003_rule_packet+0xaf>
mov    %rax,%rbp
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <ut2003_strdup@plt>
test   %rax,%rax
je     11ff <ut2003_rule_packet+0xaf>
mov    %rax,%r12
mov    %rbp,%rdi
lea    0xe40(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11d5 <ut2003_rule_packet+0x85>
mov    %r12,%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    $0xd,%ecx
call   1050 <add_rule@plt>
test   %rax,%rax
jne    1180 <ut2003_rule_packet+0x30>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
jmp    1180 <ut2003_rule_packet+0x30>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.qserver = type { i32 }
@.str = [11 x i8] c"minplayers\00"
define i32 @ut2003_rule_packet(%struct.qserver* %0, i8* %1, i8* %2) {
%4 = alloca %struct.qserver*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store %struct.qserver* %0, %struct.qserver** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %9
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %5
br label %12
12: ; preds = %46, %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = icmp ult i8* %13, %14
br i1 %15, label %16, label %47
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i8* @ut2003_strdup(i8* %17, i8* %18, i8** %5)
store i8* %19, i8** %7
%20 = icmp eq i8* null, %19
br i1 %20, label %21, label %22
21: ; preds = %16
br label %47
22: ; preds = %16
%23 = load i8*, i8** %5
%24 = load i8*, i8** %6
%25 = call i8* @ut2003_strdup(i8* %23, i8* %24, i8** %5)
store i8* %25, i8** %8
%26 = icmp eq i8* null, %25
br i1 %26, label %27, label %28
27: ; preds = %22
br label %47
28: ; preds = %22
%29 = load i8*, i8** %7
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %8
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %9
br label %35
35: ; preds = %32, %28
%36 = load %struct.qserver*, %struct.qserver** %4
%37 = load i8*, i8** %7
%38 = load i8*, i8** %8
%39 = call i32* @add_rule(%struct.qserver* %36, i8* %37, i8* %38, i32 13)
%40 = icmp eq i32* null, %39
br i1 %40, label %41, label %46
41: ; preds = %35
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %41, %35
br label %12
47: ; preds = %27, %21, %12
%48 = load i32, i32* %9
ret i32 %48
}

LLVM IR (-O2):
%struct.qserver = type { i32 }
@.str = [11 x i8] c"minplayers\00"
define i32 @ut2003_rule_packet(%struct.qserver* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = getelementptr inbounds i8, i8* %1, i64 1
store i8* %5, i8** %4
%6 = icmp ult i8* %5, %2
br i1 %6, label %7, label %31
7: ; preds = %3, %28
%8 = phi i8* [ %29, %28 ], [ %5, %3 ]
%9 = phi i32 [ %22, %28 ], [ 0, %3 ]
%10 = call i8* @ut2003_strdup(i8* %8, i8* %2, i8** %4)
%11 = icmp eq i8* %10, null
br i1 %11, label %31, label %12
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = call i8* @ut2003_strdup(i8* %13, i8* %2, i8** %4)
%15 = icmp eq i8* %14, null
br i1 %15, label %31, label %16
16: ; preds = %12
%17 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @atoi(i8* %14)
br label %21
21: ; preds = %19, %16
%22 = phi i32 [ %20, %19 ], [ %9, %16 ]
%23 = call i32* @add_rule(%struct.qserver* %0, i8* %10, i8* %14, i32 13)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @free(i8* %14)
%27 = call i32 @free(i8* %10)
br label %28
28: ; preds = %25, %21
%29 = load i8*, i8** %4
%30 = icmp ult i8* %29, %2
br i1 %30, label %7, label %31
31: ; preds = %28, %7, %12, %3
%32 = phi i32 [ 0, %3 ], [ %9, %12 ], [ %9, %7 ], [ %22, %28 ]
ret i32 %32
}