#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 option {
  int dummy;
};

/* Variables and functions */
int get_any_index(struct option *, char const *);
int get_next_index(int /*<<< orphan*/, struct option *, int /*<<< orphan*/ *);
struct option *getoptions(char *);
int /*<<< orphan*/ setopt_wonlost(char *, char const *, char const *, char *);
void add_wonlost_stats(const char *me, const char *opp, int won) {
  struct option *first = getoptions("wonlost");
  char key[4] = "";
  int i = get_next_index(0, first, NULL);
  if (i >= 640)
    i = get_any_index(first, me);
  key[0] = 'a' + i / 26;
  key[1] = 'a' + i % 26;
  setopt_wonlost(key, me, opp, won ? "1-0" : "0-1");
}


x86 assembly (clang, -O0):
<add_wonlost_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <getoptions@plt>
mov    %rax,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <get_next_index@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x280,-0x28(%rbp)
jl     11b2 <add_wonlost_stats+0x62>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <get_any_index@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%eax
mov    %al,-0x24(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    %dl,%al
mov    %al,-0x23(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%r8d
lea    0xe1f(%rip),%rcx
lea    0xe14(%rip),%rax
cmp    $0x0,%r8d
cmovne %rax,%rcx
call   1060 <setopt_wonlost@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_wonlost_stats>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea9(%rip),%rdi
call   1030 <getoptions@plt>
mov    %rax,%rbp
movl   $0x0,0x4(%rsp)
xor    %edi,%edi
mov    %rax,%rsi
xor    %edx,%edx
call   1060 <get_next_index@plt>
cmp    $0x280,%eax
jl     1185 <add_wonlost_stats+0x45>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <get_any_index@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    0x61(%rcx),%edx
mov    %dl,0x4(%rsp)
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x61,%al
mov    %al,0x5(%rsp)
test   %r15d,%r15d
lea    0xe50(%rip),%rax
lea    0xe45(%rip),%rcx
cmove  %rax,%rcx
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <setopt_wonlost@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i32 }
@.str = [8 x i8] c"wonlost\00"
@.str.1 = [4 x i8] c"1-0\00"
@.str.2 = [4 x i8] c"0-1\00"
define void @add_wonlost_stats(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.option*
%8 = alloca [4 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = call %struct.option* @getoptions(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store %struct.option* %10, %struct.option** %7
%11 = bitcast [4 x i8]* %8 to i8*
%12 = load %struct.option*, %struct.option** %7
%13 = call i32 @get_next_index(i32 0, %struct.option* %12, i32* null)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp sge i32 %14, 640
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load %struct.option*, %struct.option** %7
%18 = load i8*, i8** %4
%19 = call i32 @get_any_index(%struct.option* %17, i8* %18)
store i32 %19, i32* %9
br label %20
20: ; preds = %16, %3
%21 = load i32, i32* %9
%22 = sdiv i32 %21, 26
%23 = add nsw i32 97, %22
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
store i8 %24, i8* %25
%26 = load i32, i32* %9
%27 = srem i32 %26, 26
%28 = add nsw i32 97, %27
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 %29, i8* %30
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%38 = call i32 @setopt_wonlost(i8* %31, i8* %32, i8* %33, i8* %37)
ret void
}

LLVM IR (-O2):
%struct.option = type { i32 }
@.str = [8 x i8] c"wonlost\00"
@.str.1 = [4 x i8] c"1-0\00"
@.str.2 = [4 x i8] c"0-1\00"
define void @add_wonlost_stats(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = tail call %struct.option* @getoptions(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = tail call i32 @get_next_index(i32 0, %struct.option* %5, i32* null)
%8 = icmp sgt i32 %7, 639
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @get_any_index(%struct.option* %5, i8* %0)
br label %11
11: ; preds = %9, %3
%12 = phi i32 [ %10, %9 ], [ %7, %3 ]
%13 = bitcast i32* %4 to [4 x i8]*
%14 = sdiv i32 %12, 26
%15 = trunc i32 %14 to i8
%16 = add i8 %15, 97
store i8 %16, i8* %6
%17 = srem i32 %12, 26
%18 = trunc i32 %17 to i8
%19 = add nsw i8 %18, 97
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 1
store i8 %19, i8* %20
%21 = icmp eq i32 %2, 0
%22 = select i1 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%23 = call i32 @setopt_wonlost(i8* %6, i8* %0, i8* %1, i8* %22)
ret void
}