#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  char *player1 = malloc(51);
  char *player2 = malloc(51);
  if (player1 == NULL || player2 == NULL) {
    printf("Out of memory\n");
    return 1;
  }
  int player1dice1, player1dice2, player2dice1, player2dice2;
  printf("Spelare 1: ");
  fgets(player1, 51, stdin);
  if ((strlen(player1) > 0) && (player1[strlen(player1) - 1] == '\n')) {
    player1[strlen(player1) - 1] = '\0';
  }
  printf("Spelare 2: ");
  fgets(player2, 51, stdin);
  if ((strlen(player2) > 0) && (player2[strlen(player2) - 1] == '\n')) {
    player2[strlen(player2) - 1] = '\0';
  }
  printf("\n");
  srand(time(NULL));
  player1dice1 = rand() % 6 + 1;
  player1dice2 = rand() % 6 + 1;
  player2dice1 = rand() % 6 + 1;
  player2dice2 = rand() % 6 + 1;
  printf("Tärningskast för %s: %d och %d\n", player1, player1dice1,
         player1dice2);
  printf("Tärningskast för %s: %d och %d\n", player2, player2dice1,
         player2dice2);
  printf("\n");
  printf("%s fick resultatet %d\n", player1, player1dice1 + player1dice2);
  printf("%s fick resultatet %d\n", player2, player2dice1 + player2dice2);
  free(player1);
  player1 = NULL;
  free(player2);
  player2 = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x33,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x33,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c1 <main+0x41>
cmpq   $0x0,-0x18(%rbp)
jne    11db <main+0x5b>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13e8 <main+0x268>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    $0x33,%esi
call   1070 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    125d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    125d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d72(%rip),%rax
mov    (%rax),%edx
mov    $0x33,%esi
call   1070 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    12df <main+0x15f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    12df <main+0x15f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xcc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xcad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xcbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    -0x20(%rbp),%edx
lea    0xca9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    -0x28(%rbp),%edx
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x33,%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
mov    $0x33,%edi
call   10b0 <malloc@plt>
test   %r12,%r12
je     13b8 <main+0x218>
mov    %rax,%rbp
test   %rax,%rax
je     13b8 <main+0x218>
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dfc(%rip),%r14
mov    (%r14),%edx
mov    %r12,%rdi
mov    $0x33,%esi
call   1090 <fgets@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    122a <main+0x8a>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r12,1)
jne    122a <main+0x8a>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
lea    0xddb(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r14),%edx
mov    %rbp,%rdi
mov    $0x33,%esi
call   1090 <fgets@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1274 <main+0xd4>
mov    %rbp,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    1274 <main+0xd4>
mov    %rbp,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
mov    %rbp,(%rsp)
lea    (%rax,%rcx,1),%r14d
add    $0x1,%r14d
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r13d
add    $0x1,%r13d
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r15d
add    $0x1,%r15d
lea    0xcd3(%rip),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    (%rsp),%rbx
mov    %rbx,%rsi
mov    %r13d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    %r14d,%ebp
lea    0xcb8(%rip),%r14
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
add    %r13d,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    13c9 <main+0x229>
lea    0xc92(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory\0A\00"
@.str.1 = [12 x i8] c"Spelare 1: \00"
@stdin = global i32 0
@.str.2 = [12 x i8] c"Spelare 2: \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [34 x i8] c"T\C3\A4rningskast f\C3\B6r %s: %d och %d\0A\00"
@.str.5 = [23 x i8] c"%s fick resultatet %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i8* @malloc(i32 51)
store i8* %8, i8** %2
%9 = call i8* @malloc(i32 51)
store i8* %9, i8** %3
%10 = load i8*, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12, %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %106
17: ; preds = %12
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %19, i32 51, i32 %20)
%22 = load i8*, i8** %2
%23 = call i32 @strlen(i8* %22)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %17
%26 = load i8*, i8** %2
%27 = load i8*, i8** %2
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %42
35: ; preds = %25
%36 = load i8*, i8** %2
%37 = load i8*, i8** %2
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %35, %25, %17
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%44 = load i8*, i8** %3
%45 = load i32, i32* @stdin
%46 = call i32 @fgets(i8* %44, i32 51, i32 %45)
%47 = load i8*, i8** %3
%48 = call i32 @strlen(i8* %47)
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %67
50: ; preds = %42
%51 = load i8*, i8** %3
%52 = load i8*, i8** %3
%53 = call i32 @strlen(i8* %52)
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %51, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 10
br i1 %59, label %60, label %67
60: ; preds = %50
%61 = load i8*, i8** %3
%62 = load i8*, i8** %3
%63 = call i32 @strlen(i8* %62)
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %61, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %60, %50, %42
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%69 = call i32 @time(i32* null)
%70 = call i32 @srand(i32 %69)
%71 = call i32 (...) @rand()
%72 = srem i32 %71, 6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %4
%74 = call i32 (...) @rand()
%75 = srem i32 %74, 6
%76 = add nsw i32 %75, 1
store i32 %76, i32* %5
%77 = call i32 (...) @rand()
%78 = srem i32 %77, 6
%79 = add nsw i32 %78, 1
store i32 %79, i32* %6
%80 = call i32 (...) @rand()
%81 = srem i32 %80, 6
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
%83 = load i8*, i8** %2
%84 = load i32, i32* %4
%85 = load i32, i32* %5
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %83, i32 %84, i32 %85)
%87 = load i8*, i8** %3
%88 = load i32, i32* %6
%89 = load i32, i32* %7
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %87, i32 %88, i32 %89)
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%92 = load i8*, i8** %2
%93 = load i32, i32* %4
%94 = load i32, i32* %5
%95 = add nsw i32 %93, %94
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %92, i32 %95)
%97 = load i8*, i8** %3
%98 = load i32, i32* %6
%99 = load i32, i32* %7
%100 = add nsw i32 %98, %99
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %97, i32 %100)
%102 = load i8*, i8** %2
%103 = call i32 @free(i8* %102)
store i8* null, i8** %2
%104 = load i8*, i8** %3
%105 = call i32 @free(i8* %104)
store i8* null, i8** %3
store i32 0, i32* %1
br label %106
106: ; preds = %67, %15
%107 = load i32, i32* %1
ret i32 %107
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"Spelare 1: \00"
@stdin = global i32 0
@.str.2 = [12 x i8] c"Spelare 2: \00"
@.str.4 = [34 x i8] c"T\C3\A4rningskast f\C3\B6r %s: %d och %d\0A\00"
@.str.5 = [23 x i8] c"%s fick resultatet %d\0A\00"
@str = [14 x i8] c"Out of memory\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(51) i8* @malloc(i32 51)
%2 = tail call dereferenceable_or_null(51) i8* @malloc(i32 51)
%3 = icmp eq i8* %1, null
%4 = icmp eq i8* %2, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %69
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = tail call i32 @fgets(i8* %1, i32 51, i32 %10)
%12 = tail call i32 @strlen(i8* %1)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %8
%15 = tail call i32 @strlen(i8* %1)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = tail call i32 @strlen(i8* %1)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %21, %14, %8
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = tail call i32 @fgets(i8* %2, i32 51, i32 %28)
%30 = tail call i32 @strlen(i8* %2)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %26
%33 = tail call i32 @strlen(i8* %2)
%34 = add nsw i32 %33, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %2, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 10
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = tail call i32 @strlen(i8* %2)
%41 = add nsw i32 %40, -1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %2, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %39, %32, %26
%45 = tail call i32 @putchar(i32 10)
%46 = tail call i32 @time(i32* null)
%47 = tail call i32 @srand(i32 %46)
%48 = tail call i32 (...) @rand()
%49 = srem i32 %48, 6
%50 = add nsw i32 %49, 1
%51 = tail call i32 (...) @rand()
%52 = srem i32 %51, 6
%53 = add nsw i32 %52, 1
%54 = tail call i32 (...) @rand()
%55 = srem i32 %54, 6
%56 = add nsw i32 %55, 1
%57 = tail call i32 (...) @rand()
%58 = srem i32 %57, 6
%59 = add nsw i32 %58, 1
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %50, i32 %53)
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 %56, i32 %59)
%62 = tail call i32 @putchar(i32 10)
%63 = add nsw i32 %53, %50
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %1, i32 %63)
%65 = add nsw i32 %59, %56
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %2, i32 %65)
%67 = tail call i32 @free(i8* %1)
%68 = tail call i32 @free(i8* %2)
br label %69
69: ; preds = %44, %6
%70 = phi i32 [ 1, %6 ], [ 0, %44 ]
ret i32 %70
}