#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*/ time_t;
struct tm {
  int dummy;
};
struct passwd {
  char *pw_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ err_exit(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int const,
                           char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ geteuid();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ gettext(char *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(scalar_t__);
int mkdir(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void save_score(const int time_taken) {
  time_t tm = time(NULL);
  struct tm *today = localtime(&tm);
  char tmpbuffer[129];
  today = localtime(&tm);
  char appdata_dir[4096];
  const char *score_filename = "4digits.4digits.scores";
  strcpy(appdata_dir, getenv("HOME"));
  strcat(appdata_dir, "/.4digits/");
  char *scorefile =
      (char *)malloc(strlen(appdata_dir) + strlen(score_filename) + 1);
  if (!scorefile)
    err_exit(gettext("Memory allocation error.\n"));
  strcpy(scorefile, appdata_dir);
  strcat(scorefile, score_filename);
  FILE *sfp = fopen(scorefile, "a+");
  if (!sfp) {
    if (errno == ENOENT) {
      DIR *dp = opendir(appdata_dir);
      if (!dp)
        if (errno == ENOENT) {
          int ret = mkdir(appdata_dir, 0700);
          if (ret == -1)
            err_exit(gettext("Cannot open score file.\n"));
          sfp = fopen(scorefile, "a+");
        }
    } else
      err_exit(gettext("Cannot open score file.\n"));
  }
  strftime(tmpbuffer, 128, "%a %b %d %H:%M:%S %Y", today);
  struct passwd *pwd;
  pwd = getpwuid(geteuid());
  fprintf(sfp, "%s %ds %s\n", pwd->pw_name, time_taken, tmpbuffer);
  free(scorefile);
}


x86 assembly (clang, -O0):
<save_score>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10e0,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <localtime@plt>
mov    %rax,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <localtime@plt>
mov    %rax,-0x10(%rbp)
lea    0xdb5(%rip),%rax
mov    %rax,-0x10a8(%rbp)
lea    -0x10a0(%rbp),%rax
mov    %rax,-0x10e0(%rbp)
lea    0xdb0(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x10e0(%rbp),%rdi
mov    %rax,%rsi
call   1060 <strcpy@plt>
lea    -0x10a0(%rbp),%rdi
lea    0xd93(%rip),%rsi
call   1130 <strcat@plt>
lea    -0x10a0(%rbp),%rdi
call   10a0 <strlen@plt>
mov    %rax,-0x10d8(%rbp)
mov    -0x10a8(%rbp),%rdi
call   10a0 <strlen@plt>
mov    -0x10d8(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   10f0 <malloc@plt>
mov    %rax,-0x10b0(%rbp)
cmpq   $0x0,-0x10b0(%rbp)
jne    12e8 <save_score+0xd8>
lea    0xd4b(%rip),%rdi
call   10b0 <gettext@plt>
mov    %eax,%edi
call   1100 <err_exit@plt>
mov    -0x10b0(%rbp),%rdi
lea    -0x10a0(%rbp),%rsi
call   1060 <strcpy@plt>
mov    -0x10b0(%rbp),%rdi
mov    -0x10a8(%rbp),%rsi
call   1130 <strcat@plt>
mov    -0x10b0(%rbp),%rdi
lea    0xd25(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x10b8(%rbp)
cmpq   $0x0,-0x10b8(%rbp)
jne    13fe <save_score+0x1ee>
mov    0x2ca3(%rip),%rax
mov    (%rax),%rax
mov    0x2c89(%rip),%rcx
cmp    (%rcx),%rax
jne    13e6 <save_score+0x1d6>
lea    -0x10a0(%rbp),%rdi
call   1080 <opendir@plt>
mov    %rax,-0x10c0(%rbp)
cmpq   $0x0,-0x10c0(%rbp)
jne    13e1 <save_score+0x1d1>
mov    0x2c68(%rip),%rax
mov    (%rax),%rax
mov    0x2c4e(%rip),%rcx
cmp    (%rcx),%rax
jne    13dc <save_score+0x1cc>
lea    -0x10a0(%rbp),%rdi
mov    $0x1c0,%esi
call   1070 <mkdir@plt>
mov    %eax,-0x10c4(%rbp)
cmpl   $0xffffffff,-0x10c4(%rbp)
jne    13c2 <save_score+0x1b2>
lea    0xc8e(%rip),%rdi
call   10b0 <gettext@plt>
mov    %eax,%edi
call   1100 <err_exit@plt>
mov    -0x10b0(%rbp),%rdi
lea    0xc71(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x10b8(%rbp)
jmp    13e1 <save_score+0x1d1>
jmp    13f9 <save_score+0x1e9>
lea    0xc57(%rip),%rdi
call   10b0 <gettext@plt>
mov    %eax,%edi
call   1100 <err_exit@plt>
jmp    13fe <save_score+0x1ee>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x80,%esi
lea    0xc48(%rip),%rdx
call   1110 <strftime@plt>
mov    $0x0,%al
call   10c0 <geteuid@plt>
mov    %eax,%edi
call   1090 <getpwuid@plt>
mov    %rax,-0x10d0(%rbp)
mov    -0x10b8(%rbp),%rdi
mov    -0x10d0(%rbp),%rax
mov    (%rax),%rdx
mov    -0x4(%rbp),%ecx
lea    -0xa0(%rbp),%r8
lea    0xc21(%rip),%rsi
call   10d0 <fprintf@plt>
mov    -0x10b0(%rbp),%rdi
call   1040 <free@plt>
add    $0x10e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_score>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10a0,%rsp
mov    %edi,%r14d
xor    %edi,%edi
call   10e0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <localtime@plt>
mov    %rbx,%rdi
call   1050 <localtime@plt>
mov    %rax,%r15
lea    0xdcb(%rip),%rdi
call   1030 <getenv@plt>
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <strcpy@plt>
lea    0xdb1(%rip),%rsi
mov    %rbx,%rdi
call   1130 <strcat@plt>
mov    %rbx,%rdi
call   10a0 <strlen@plt>
lea    0x17(%rax),%rdi
call   10f0 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    129f <save_score+0x8f>
lea    0xd94(%rip),%rdi
call   10b0 <gettext@plt>
mov    %eax,%edi
call   1100 <err_exit@plt>
lea    0xa0(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <strcpy@plt>
lea    0xd4a(%rip),%rsi
mov    %rbp,%rdi
call   1130 <strcat@plt>
lea    0xd7c(%rip),%rsi
mov    %rbp,%rdi
call   1120 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    135e <save_score+0x14e>
mov    0x2d00(%rip),%r12
mov    (%r12),%rax
mov    0x2ce5(%rip),%rbx
cmp    (%rbx),%rax
jne    1349 <save_score+0x139>
lea    0xa0(%rsp),%rdi
call   1080 <opendir@plt>
test   %rax,%rax
jne    135c <save_score+0x14c>
mov    (%r12),%rax
cmp    (%rbx),%rax
jne    135c <save_score+0x14c>
lea    0xa0(%rsp),%rdi
mov    $0x1c0,%esi
call   1070 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1335 <save_score+0x125>
lea    0xd1b(%rip),%rdi
call   10b0 <gettext@plt>
mov    %eax,%edi
call   1100 <err_exit@plt>
lea    0xd05(%rip),%rsi
mov    %rbp,%rdi
call   1120 <fopen@plt>
mov    %rax,%rbx
jmp    135e <save_score+0x14e>
lea    0xcf4(%rip),%rdi
call   10b0 <gettext@plt>
mov    %eax,%edi
call   1100 <err_exit@plt>
xor    %ebx,%ebx
lea    0xcf8(%rip),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x80,%esi
mov    %r15,%rcx
call   1110 <strftime@plt>
xor    %eax,%eax
call   10c0 <geteuid@plt>
mov    %eax,%edi
call   1090 <getpwuid@plt>
mov    (%rax),%rdx
lea    0xce0(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%ecx
mov    %r12,%r8
call   10d0 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
add    $0x10a0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.passwd = type { i8* }
@.str = [23 x i8] c"4digits.4digits.scores\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [11 x i8] c"/.4digits/\00"
@.str.3 = [26 x i8] c"Memory allocation error.\0A\00"
@.str.4 = [3 x i8] c"a+\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.5 = [25 x i8] c"Cannot open score file.\0A\00"
@.str.6 = [21 x i8] c"%a %b %d %H:%M:%S %Y\00"
@.str.7 = [11 x i8] c"%s %ds %s\0A\00"
define void @save_score(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca [129 x i8]
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca %struct.passwd*
store i32 %0, i32* %2
%13 = call i32 @time(i32* null)
store i32 %13, i32* %3
%14 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %14, %struct.tm** %4
%15 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %15, %struct.tm** %4
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %7
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%17 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = load i8*, i8** %7
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %22, %24
%26 = add nsw i64 %25, 1
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %1
%32 = call i32 @gettext(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @err_exit(i32 %32)
br label %34
34: ; preds = %31, %1
%35 = load i8*, i8** %8
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %8
%39 = load i8*, i8** %7
%40 = call i32 @strcat(i8* %38, i8* %39)
%41 = load i8*, i8** %8
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %42, i32** %9
%43 = load i32*, i32** %9
%44 = icmp ne i32* %43, null
br i1 %44, label %75, label %45
45: ; preds = %34
%46 = load i64, i64* @errno
%47 = load i64, i64* @ENOENT
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %71
49: ; preds = %45
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%51 = call i32* @opendir(i8* %50)
store i32* %51, i32** %10
%52 = load i32*, i32** %10
%53 = icmp ne i32* %52, null
br i1 %53, label %70, label %54
54: ; preds = %49
%55 = load i64, i64* @errno
%56 = load i64, i64* @ENOENT
%57 = icmp eq i64 %55, %56
br i1 %57, label %58, label %69
58: ; preds = %54
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%60 = call i32 @mkdir(i8* %59, i32 448)
store i32 %60, i32* %11
%61 = load i32, i32* %11
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = call i32 @gettext(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%65 = call i32 @err_exit(i32 %64)
br label %66
66: ; preds = %63, %58
%67 = load i8*, i8** %8
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %68, i32** %9
br label %69
69: ; preds = %66, %54
br label %70
70: ; preds = %69, %49
br label %74
71: ; preds = %45
%72 = call i32 @gettext(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%73 = call i32 @err_exit(i32 %72)
br label %74
74: ; preds = %71, %70
br label %75
75: ; preds = %74, %34
%76 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%77 = load %struct.tm*, %struct.tm** %4
%78 = call i32 @strftime(i8* %76, i32 128, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), %struct.tm* %77)
%79 = call i32 (...) @geteuid()
%80 = call %struct.passwd* @getpwuid(i32 %79)
store %struct.passwd* %80, %struct.passwd** %12
%81 = load i32*, i32** %9
%82 = load %struct.passwd*, %struct.passwd** %12
%83 = getelementptr inbounds %struct.passwd, %struct.passwd* %82, i32 0, i32 0
%84 = load i8*, i8** %83
%85 = load i32, i32* %2
%86 = getelementptr inbounds [129 x i8], [129 x i8]* %5, i64 0, i64 0
%87 = call i32 @fprintf(i32* %81, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %84, i32 %85, i8* %86)
%88 = load i8*, i8** %8
%89 = call i32 @free(i8* %88)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
%struct.passwd = type { i8* }
@.str = [23 x i8] c"4digits.4digits.scores\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [11 x i8] c"/.4digits/\00"
@.str.3 = [26 x i8] c"Memory allocation error.\0A\00"
@.str.4 = [3 x i8] c"a+\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.5 = [25 x i8] c"Cannot open score file.\0A\00"
@.str.6 = [21 x i8] c"%a %b %d %H:%M:%S %Y\00"
@.str.7 = [11 x i8] c"%s %ds %s\0A\00"
define void @save_score(i32 %0) {
%2 = alloca i32
%3 = alloca [129 x i8]
%4 = alloca [4096 x i8]
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %2
%7 = call %struct.tm* @localtime(i32* %2)
%8 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%9 = call %struct.tm* @localtime(i32* %2)
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%14 = call i64 @strlen(i8* %10)
%15 = add nsw i64 %14, 23
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %22
19: ; preds = %1
%20 = call i32 @gettext(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @err_exit(i32 %20)
br label %22
22: ; preds = %19, %1
%23 = call i32 @strcpy(i8* %17, i8* %10)
%24 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%25 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %49
27: ; preds = %22
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = call i32* @opendir(i8* %10)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %49
34: ; preds = %31
%35 = load i64, i64* @errno
%36 = load i64, i64* @ENOENT
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = call i32 @mkdir(i8* %10, i32 448)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @gettext(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @err_exit(i32 %42)
br label %44
44: ; preds = %41, %38
%45 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %49
46: ; preds = %27
%47 = call i32 @gettext(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @err_exit(i32 %47)
br label %49
49: ; preds = %31, %44, %34, %46, %22
%50 = phi i32* [ %25, %22 ], [ null, %46 ], [ null, %31 ], [ %45, %44 ], [ null, %34 ]
%51 = call i32 @strftime(i8* %8, i32 128, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), %struct.tm* %9)
%52 = call i32 (...) @geteuid()
%53 = call %struct.passwd* @getpwuid(i32 %52)
%54 = getelementptr inbounds %struct.passwd, %struct.passwd* %53, i64 0, i32 0
%55 = load i8*, i8** %54
%56 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %55, i32 %0, i8* %8)
%57 = call i32 @free(i8* %17)
ret void
}