#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*/ printf(char *, int, int, int, int);
scalar_t__ rating_change_draw(int, int);
scalar_t__ rating_change_loss(int, int);
scalar_t__ rating_change_win(int, int);
int rating_compute_new_rating(int old_rating, int opponent_rating, int result,
                              int num_games) {
  int rating;
  printf("er %i or %i r %i n %i\n", old_rating, opponent_rating, result,
         num_games);
  if (num_games <= 20) {
    rating = (num_games - 1) * old_rating;
    rating += opponent_rating + result * 400;
    rating /= num_games;
  } else {
    rating = old_rating;
    if (result > 0)
      rating += rating_change_win(old_rating, opponent_rating);
    else if (result < 0)
      rating += rating_change_loss(old_rating, opponent_rating);
    else
      rating += rating_change_draw(old_rating, opponent_rating);
  }
  return rating;
}


x86 assembly (clang, -O0):
<rating_compute_new_rating>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x14,-0x10(%rbp)
jg     11a7 <rating_compute_new_rating+0x67>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
imul   -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
imul   $0x190,-0xc(%rbp),%ecx
add    %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    121d <rating_compute_new_rating+0xdd>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11d4 <rating_compute_new_rating+0x94>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <rating_change_win@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1218 <rating_compute_new_rating+0xd8>
cmpl   $0x0,-0xc(%rbp)
jge    11fb <rating_compute_new_rating+0xbb>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <rating_change_loss@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1213 <rating_compute_new_rating+0xd3>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <rating_change_draw@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1218 <rating_compute_new_rating+0xd8>
jmp    121d <rating_compute_new_rating+0xdd>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rating_compute_new_rating>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%r14d
lea    0xea8(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
call   1040 <printf@plt>
cmp    $0x14,%ebx
jg     1184 <rating_compute_new_rating+0x44>
lea    -0x1(%rbx),%ecx
imul   %r14d,%ecx
imul   $0x190,%ebp,%eax
add    %r15d,%eax
add    %ecx,%eax
cltd
idiv   %ebx
jmp    11a6 <rating_compute_new_rating+0x66>
mov    %r14d,%edi
mov    %r15d,%esi
test   %ebp,%ebp
jle    1195 <rating_compute_new_rating+0x55>
call   1050 <rating_change_win@plt>
jmp    11a3 <rating_compute_new_rating+0x63>
js     119e <rating_compute_new_rating+0x5e>
call   1030 <rating_change_draw@plt>
jmp    11a3 <rating_compute_new_rating+0x63>
call   1060 <rating_change_loss@plt>
add    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"er %i or %i r %i n %i\0A\00"
define i32 @rating_compute_new_rating(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11, i32 %12, i32 %13)
%15 = load i32, i32* %8
%16 = icmp sle i32 %15, 20
br i1 %16, label %17, label %31
17: ; preds = %4
%18 = load i32, i32* %8
%19 = sub nsw i32 %18, 1
%20 = load i32, i32* %5
%21 = mul nsw i32 %19, %20
store i32 %21, i32* %9
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = mul nsw i32 %23, 400
%25 = add nsw i32 %22, %24
%26 = load i32, i32* %9
%27 = add nsw i32 %26, %25
store i32 %27, i32* %9
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = sdiv i32 %29, %28
store i32 %30, i32* %9
br label %64
31: ; preds = %4
%32 = load i32, i32* %5
store i32 %32, i32* %9
%33 = load i32, i32* %7
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %31
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = call i64 @rating_change_win(i32 %36, i32 %37)
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = add nsw i64 %40, %38
%42 = trunc i64 %41 to i32
store i32 %42, i32* %9
br label %63
43: ; preds = %31
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i32, i32* %5
%48 = load i32, i32* %6
%49 = call i64 @rating_change_loss(i32 %47, i32 %48)
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = add nsw i64 %51, %49
%53 = trunc i64 %52 to i32
store i32 %53, i32* %9
br label %62
54: ; preds = %43
%55 = load i32, i32* %5
%56 = load i32, i32* %6
%57 = call i64 @rating_change_draw(i32 %55, i32 %56)
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %9
br label %62
62: ; preds = %54, %46
br label %63
63: ; preds = %62, %35
br label %64
64: ; preds = %63, %17
%65 = load i32, i32* %9
ret i32 %65
}

LLVM IR (-O2):
@.str = [23 x i8] c"er %i or %i r %i n %i\0A\00"
define i32 @rating_compute_new_rating(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2, i32 %3)
%6 = icmp slt i32 %3, 21
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = add nsw i32 %3, -1
%9 = mul nsw i32 %8, %0
%10 = mul nsw i32 %2, 400
%11 = add nsw i32 %10, %1
%12 = add nsw i32 %11, %9
%13 = sdiv i32 %12, %3
br label %30
14: ; preds = %4
%15 = icmp sgt i32 %2, 0
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = tail call i64 @rating_change_win(i32 %0, i32 %1)
%18 = trunc i64 %17 to i32
%19 = add i32 %18, %0
br label %30
20: ; preds = %14
%21 = icmp slt i32 %2, 0
br i1 %21, label %22, label %26
22: ; preds = %20
%23 = tail call i64 @rating_change_loss(i32 %0, i32 %1)
%24 = trunc i64 %23 to i32
%25 = add i32 %24, %0
br label %30
26: ; preds = %20
%27 = tail call i64 @rating_change_draw(i32 %0, i32 %1)
%28 = trunc i64 %27 to i32
%29 = add i32 %28, %0
br label %30
30: ; preds = %16, %26, %22, %7
%31 = phi i32 [ %13, %7 ], [ %19, %16 ], [ %25, %22 ], [ %29, %26 ]
ret i32 %31
}