#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 rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int die, lastdie, count, unfinished, throws;
  char *dienames[] = {"ettor", "tvåor", "treor", "fyror", "femmor", "sexor"};
  srand(time(NULL));
  printf("Detta program kastar tärning tills vi fått tre lika i rad\n");
  count = 0;
  unfinished = 1;
  lastdie = 0;
  throws = 0;
  while (unfinished) {
    throws++;
    die = rand() % 6 + 1;
    printf("Kast %d gav %d prickar\n", throws, die);
    if (die == lastdie)
      count++;
    else
      count = 0;
    lastdie = die;
    unfinished = count != 2;
  }
  printf("Vi fick tre stycken %s efter %d kast\n", dienames[die - 1], throws);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    0xe8a(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe85(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe7c(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1262 <main+0x112>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1241 <main+0xf1>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1248 <main+0xf8>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    11eb <main+0x9b>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x50(%rbp,%rax,8),%rsi
mov    -0x18(%rbp),%edx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe9b(%rip),%rax
mov    %rax,(%rsp)
lea    0xe96(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe91(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe8b(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe85(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe80(%rip),%rax
mov    %rax,0x28(%rsp)
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
xor    %r13d,%r13d
xor    %ebx,%ebx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
xor    %eax,%eax
call   1070 <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),%r14d
mov    %r14d,%eax
neg    %eax
lea    (%r15,%rax,1),%ebp
add    $0x1,%ebp
lea    0xe19(%rip),%rdi
mov    %r13d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    %r12d,%ebp
mov    $0x0,%eax
cmovne %eax,%ebx
mov    %ebp,%r12d
cmp    $0x2,%ebx
jne    11d0 <main+0x80>
sub    %r14d,%r15d
movslq %r15d,%rax
mov    (%rsp,%rax,8),%rsi
lea    0xdfe(%rip),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ettor\00"
@.str.1 = [7 x i8] c"tv\C3\A5or\00"
@.str.2 = [6 x i8] c"treor\00"
@.str.3 = [6 x i8] c"fyror\00"
@.str.4 = [7 x i8] c"femmor\00"
@.str.5 = [6 x i8] c"sexor\00"
@.str.6 = [61 x i8] c"Detta program kastar t\C3\A4rning tills vi f\C3\A5tt tre lika i rad\0A\00"
@.str.7 = [24 x i8] c"Kast %d gav %d prickar\0A\00"
@.str.8 = [38 x i8] c"Vi fick tre stycken %s efter %d kast\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [6 x i8*]
store i32 0, i32* %1
%8 = bitcast [6 x i8*]* %7 to i8*
%9 = bitcast i8* %8 to [6 x i8*]*
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i8** %15
%16 = call i32 @time(i32* null)
%17 = call i32 @srand(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
store i32 1, i32* %5
store i32 0, i32* %3
store i32 0, i32* %6
br label %19
19: ; preds = %38, %0
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
%28 = load i32, i32* %6
%29 = load i32, i32* %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %28, i32 %29)
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %22
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %38
37: ; preds = %22
store i32 0, i32* %4
br label %38
38: ; preds = %37, %34
%39 = load i32, i32* %2
store i32 %39, i32* %3
%40 = load i32, i32* %4
%41 = icmp ne i32 %40, 2
%42 = zext i1 %41 to i32
store i32 %42, i32* %5
br label %19
43: ; preds = %19
%44 = load i32, i32* %2
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = load i32, i32* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %48, i32 %49)
ret i32 1
}

LLVM IR (-O2):
@.str = [6 x i8] c"ettor\00"
@.str.1 = [7 x i8] c"tv\C3\A5or\00"
@.str.2 = [6 x i8] c"treor\00"
@.str.3 = [6 x i8] c"fyror\00"
@.str.4 = [7 x i8] c"femmor\00"
@.str.5 = [6 x i8] c"sexor\00"
@.str.7 = [24 x i8] c"Kast %d gav %d prickar\0A\00"
@.str.8 = [38 x i8] c"Vi fick tre stycken %s efter %d kast\0A\00"
@str = [60 x i8] c"Detta program kastar t\C3\A4rning tills vi f\C3\A5tt tre lika i rad\00"
define i32 @main() {
%1 = alloca [6 x i8*]
%2 = bitcast [6 x i8*]* %1 to i8*
%3 = getelementptr inbounds [6 x i8*], [6 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = getelementptr inbounds [6 x i8*], [6 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [6 x i8*], [6 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [6 x i8*], [6 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %1, i64 0, i64 4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [6 x i8*], [6 x i8*]* %1, i64 0, i64 5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %8
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srand(i32 %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %0, %12
%13 = phi i32 [ 0, %0 ], [ %16, %12 ]
%14 = phi i32 [ 0, %0 ], [ %23, %12 ]
%15 = phi i32 [ 0, %0 ], [ %19, %12 ]
%16 = add nuw nsw i32 %13, 1
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 6
%19 = add nsw i32 %18, 1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %16, i32 %19)
%21 = icmp eq i32 %19, %15
%22 = add nsw i32 %14, 1
%23 = select i1 %21, i32 %22, i32 0
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %12
25: ; preds = %12
%26 = sext i32 %18 to i64
%27 = getelementptr inbounds [6 x i8*], [6 x i8*]* %1, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %28, i32 %16)
ret i32 1
}