#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ player_query(char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
uint8_t game_dice_throw(bool *doubles) {
  uint8_t dice1;
  uint8_t dice2;
  printf("Heita nopat painamalla enter...");
  (void)player_query("");
  dice1 = rand() % 6 + 1;
  dice2 = rand() % 6 + 1;
  printf("Silmaluvut %i ja %i = %i\n", dice1, dice2, dice1 + dice2);
  if (doubles != NULL) {
    *doubles = (dice1 == dice2);
  }
  return dice1 + dice2;
}


x86 assembly (clang, -O0):
<game_dice_throw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
call   1040 <player_query@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
je     11b9 <game_dice_throw+0x89>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<game_dice_throw>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
call   1040 <player_query@plt>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%r15d
cltq
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%r13d
mov    %r13d,%eax
neg    %eax
lea    (%r15,%rax,1),%r12d
add    $0x1,%r12d
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ebx
cltq
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%r14d
mov    %r14d,%eax
neg    %eax
lea    (%rbx,%rax,1),%edx
add    $0x1,%edx
lea    (%rdx,%r12,1),%ebp
lea    0xe59(%rip),%rdi
mov    %r12d,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     11ec <game_dice_throw+0xbc>
sub    %r13d,%r15d
sub    %r14d,%ebx
xor    %eax,%eax
cmp    %ebx,%r15d
sete   %al
mov    %eax,(%rcx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Heita nopat painamalla enter...\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [26 x i8] c"Silmaluvut %i ja %i = %i\0A\00"
define i32 @game_dice_throw(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @player_query(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 6
%9 = add nsw i32 %8, 1
store i32 %9, i32* %3
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 6
%12 = add nsw i32 %11, 1
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = add nsw i32 %15, %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14, i32 %17)
%19 = load i32*, i32** %2
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %1
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = icmp eq i32 %22, %23
%25 = zext i1 %24 to i32
%26 = load i32*, i32** %2
store i32 %25, i32* %26
br label %27
27: ; preds = %21, %1
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = add nsw i32 %28, %29
ret i32 %30
}

LLVM IR (-O2):
@.str = [32 x i8] c"Heita nopat painamalla enter...\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [26 x i8] c"Silmaluvut %i ja %i = %i\0A\00"
define i32 @game_dice_throw(i32* writeonly %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @player_query(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 6
%6 = add nsw i32 %5, 1
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 6
%9 = add nsw i32 %8, 1
%10 = add nsw i32 %9, %6
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %9, i32 %10)
%12 = icmp eq i32* %0, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = icmp eq i32 %5, %8
%15 = zext i1 %14 to i32
store i32 %15, i32* %0
br label %16
16: ; preds = %13, %1
ret i32 %10
}