#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*/ assert(int /*<<< orphan*/);
char *calloc(int, int);
int get_local_time(char **, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int rand_x_y(int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
get_file_name(char **buffer) {
  char *buffer_tmp = NULL;
  char srval[5] = {0, 0, 0, 0, 0};
  int rval = 0;
  int size = 0;
  srand(time(NULL));
  rval = rand_x_y(1000, 9999);
  sprintf(srval, "%d", rval);
  size = get_local_time(&buffer_tmp, 0);
  assert(*buffer == NULL);
  if ((*buffer = calloc(size + 1 + 4, sizeof(char))) == NULL) {
    perror("calloc");
    return -1;
  }
  strcpy(*buffer, buffer_tmp);
  strcat(*buffer, srval);
  return (size + 4);
}


x86 assembly (clang, -O0):
<get_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x1d(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x3e8,%edi
mov    $0x270f,%esi
call   10a0 <rand_x_y@plt>
mov    %eax,-0x24(%rbp)
lea    -0x1d(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xdee(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1080 <get_local_time@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%edi
add    $0x1,%edi
add    $0x4,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1276 <get_file_name+0xc6>
lea    0xd9e(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <get_file_name+0xef>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x1d(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x28(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_name>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movq   $0x0,0x10(%rsp)
movb   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x3e8,%edi
mov    $0x270f,%esi
call   1090 <rand_x_y@plt>
lea    0xe1c(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %eax,%edx
call   10c0 <sprintf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <get_local_time@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmpq   $0x0,(%r14)
sete   %dil
call   1060 <assert@plt>
lea    0x5(%rbx),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1249 <get_file_name+0xa9>
mov    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    (%r14),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <strcat@plt>
add    $0x4,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdb3(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%ebx
jmp    123f <get_file_name+0x9f>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"calloc\00"
define i32 @get_file_name(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca [5 x i8]
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %3
store i8* null, i8** %4
%8 = bitcast [5 x i8]* %5 to i8*
store i32 0, i32* %6
store i32 0, i32* %7
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
%11 = call i32 @rand_x_y(i32 1000, i32 9999)
store i32 %11, i32* %6
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%13 = load i32, i32* %6
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @get_local_time(i8** %4, i32 0)
store i32 %15, i32* %7
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
%23 = add nsw i32 %22, 4
%24 = call i8* @calloc(i32 %23, i32 1)
%25 = load i8**, i8*** %3
store i8* %24, i8** %25
%26 = icmp eq i8* %24, null
br i1 %26, label %27, label %29
27: ; preds = %1
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %40
29: ; preds = %1
%30 = load i8**, i8*** %3
%31 = load i8*, i8** %30
%32 = load i8*, i8** %4
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i8**, i8*** %3
%35 = load i8*, i8** %34
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 4
store i32 %39, i32* %2
br label %40
40: ; preds = %29, %27
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"calloc\00"
define i32 @get_file_name(i8** nocapture %0) {
%2 = alloca i8*
%3 = alloca [5 x i8]
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @time(i32* null)
%7 = tail call i32 @srand(i32 %6)
%8 = tail call i32 @rand_x_y(i32 1000, i32 9999)
%9 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @get_local_time(i8** %2, i32 0)
%11 = load i8*, i8** %0
%12 = icmp eq i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = add nsw i32 %10, 5
%16 = call i8* @calloc(i32 %15, i32 1)
store i8* %16, i8** %0
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = call i32 @strcpy(i8* %16, i8* %21)
%23 = load i8*, i8** %0
%24 = call i32 @strcat(i8* %23, i8* %5)
%25 = add nsw i32 %10, 4
br label %26
26: ; preds = %20, %18
%27 = phi i32 [ -1, %18 ], [ %25, %20 ]
ret i32 %27
}