#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *get_habit(char *);
int get_ngates(char *);
scalar_t__ get_record_score();
char *get_reward(char *);
int get_score(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ tee_habit(int /*<<< orphan*/ *, int, char *, char *, int,
                             int);
void update_scores(FILE *f, int id, char *line) {
  bool achived = false;
  char *habit = get_habit(line);
  char *reward = get_reward(line);
  int score = get_score(line);
  score += get_record_score();
  int ngates = get_ngates(line);
  int achived_gates = score / 15;
  if (achived_gates > ngates) {
    ngates++;
    achived = true;
  }
  tee_habit(f, (int)id, habit, reward, score, ngates);
  if (achived) {
    printf("Congratulations, you passed a gate! ");
    printf("Reward yourself with: %s\n", reward);
  }
  free(habit);
  free(reward);
}


x86 assembly (clang, -O0):
<update_scores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <get_habit@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <get_reward@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <get_score@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1040 <get_record_score@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <get_ngates@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jle    120a <update_scores+0x8a>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
call   1090 <tee_habit@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1250 <update_scores+0xd0>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_scores>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %esi,0x4(%rsp)
mov    %rdi,%r12
mov    %rdx,%rdi
call   1080 <get_habit@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   10a0 <get_reward@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1070 <get_score@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <get_record_score@plt>
mov    %rax,%r15
add    %ebx,%r15d
mov    %rbp,%rdi
call   1050 <get_ngates@plt>
mov    %eax,%ebp
movslq %r15d,%r8
imul   $0xffffffff88888889,%r8,%rbx
shr    $0x20,%rbx
add    %r8d,%ebx
mov    %ebx,%eax
shr    $0x1f,%eax
sar    $0x3,%ebx
add    %eax,%ebx
xor    %r9d,%r9d
cmp    %ebp,%ebx
setg   %r9b
add    %ebp,%r9d
mov    %r12,%rdi
mov    0x4(%rsp),%esi
mov    %r14,%rdx
mov    %r13,%rcx
call   1090 <tee_habit@plt>
cmp    %ebp,%ebx
jle    1228 <update_scores+0xa8>
lea    0xdf0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe07(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Congratulations, you passed a gate! \00"
@.str.1 = [26 x i8] c"Reward yourself with: %s\0A\00"
define void @update_scores(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
%13 = load i8*, i8** %6
%14 = call i8* @get_habit(i8* %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %6
%16 = call i8* @get_reward(i8* %15)
store i8* %16, i8** %9
%17 = load i8*, i8** %6
%18 = call i32 @get_score(i8* %17)
store i32 %18, i32* %10
%19 = call i64 (...) @get_record_score()
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %10
%24 = load i8*, i8** %6
%25 = call i32 @get_ngates(i8* %24)
store i32 %25, i32* %11
%26 = load i32, i32* %10
%27 = sdiv i32 %26, 15
store i32 %27, i32* %12
%28 = load i32, i32* %12
%29 = load i32, i32* %11
%30 = icmp sgt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %3
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
store i32 1, i32* %7
br label %34
34: ; preds = %31, %3
%35 = load i32*, i32** %4
%36 = load i32, i32* %5
%37 = load i8*, i8** %8
%38 = load i8*, i8** %9
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = call i32 @tee_habit(i32* %35, i32 %36, i8* %37, i8* %38, i32 %39, i32 %40)
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %34
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%46 = load i8*, i8** %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %44, %34
%49 = load i8*, i8** %8
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %9
%52 = call i32 @free(i8* %51)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Congratulations, you passed a gate! \00"
@.str.1 = [26 x i8] c"Reward yourself with: %s\0A\00"
define void @update_scores(i32* %0, i32 %1, i8* %2) {
%4 = tail call i8* @get_habit(i8* %2)
%5 = tail call i8* @get_reward(i8* %2)
%6 = tail call i32 @get_score(i8* %2)
%7 = tail call i64 (...) @get_record_score()
%8 = trunc i64 %7 to i32
%9 = add i32 %6, %8
%10 = tail call i32 @get_ngates(i8* %2)
%11 = sdiv i32 %9, 15
%12 = icmp sgt i32 %11, %10
%13 = zext i1 %12 to i32
%14 = add nsw i32 %10, %13
%15 = tail call i32 @tee_habit(i32* %0, i32 %1, i8* %4, i8* %5, i32 %9, i32 %14)
br i1 %12, label %16, label %19
16: ; preds = %3
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %19
19: ; preds = %16, %3
%20 = tail call i32 @free(i8* %4)
%21 = tail call i32 @free(i8* %5)
ret void
}