#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, char *, int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
char *strdup(char *);
char *strerror(int);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main() {
  srand(time(0));
  int randnum = rand();
  printf("Content-Type:application/text\n\n");
  char *line = malloc(1);
  size_t s = 1;
  getline(&line, &s, stdin);
  char *extension = strdup(line);
  char *file;
  asprintf(&file, "%s/%d.json", "/srv/www/kundaje/epigenomeviz_cache", randnum);
  FILE *fout = fopen(file, "w");
  if (fout == NULL) {
    printf("ERROR: %s (%d)", strerror(errno), errno);
    return 1;
  }
  fprintf(fout, "%s", extension);
  fclose(fout);
  printf("%d.json", randnum);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    %eax,-0x8(%rbp)
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <getline@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%ecx
lea    -0x28(%rbp),%rdi
lea    0xde4(%rip),%rsi
lea    0xde8(%rip),%rdx
call   1090 <asprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    129b <main+0xdb>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x110>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdb6(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10f0 <rand@plt>
mov    %eax,%r14d
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,0x8(%rsp)
movq   $0x1,0x18(%rsp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   10c0 <getline@plt>
mov    0x8(%rsp),%rdi
call   10d0 <strdup@plt>
mov    %rax,%rbx
lea    0xdc0(%rip),%rsi
lea    0xdc4(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    %r14d,%ecx
call   10a0 <asprintf@plt>
mov    0x10(%rsp),%rdi
lea    0xdcf(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1293 <main+0xc3>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xd7c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12b4 <main+0xe4>
mov    0x2d3e(%rip),%rbx
mov    (%rbx),%edi
call   10e0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd87(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Content-Type:application/text\0A\0A\00"
@stdin = global i32 0
@.str.1 = [11 x i8] c"%s/%d.json\00"
@.str.2 = [36 x i8] c"/srv/www/kundaje/epigenomeviz_cache\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [15 x i8] c"ERROR: %s (%d)\00"
@errno = global i32 0
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [8 x i8] c"%d.json\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i32 @time(i32 0)
%9 = call i32 @srand(i32 %8)
%10 = call i32 (...) @rand()
store i32 %10, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%12 = call i8* @malloc(i32 1)
store i8* %12, i8** %3
store i64 1, i64* %4
%13 = load i32, i32* @stdin
%14 = call i32 @getline(i8** %3, i64* %4, i32 %13)
%15 = load i8*, i8** %3
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %5
%17 = load i32, i32* %2
%18 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %6
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %0
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = load i32, i32* @errno
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %25, i32 %26)
store i32 1, i32* %1
br label %36
28: ; preds = %0
%29 = load i32*, i32** %7
%30 = load i8*, i8** %5
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %7
%33 = call i32 @fclose(i32* %32)
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %34)
store i32 1, i32* %1
br label %36
36: ; preds = %28, %23
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [11 x i8] c"%s/%d.json\00"
@.str.2 = [36 x i8] c"/srv/www/kundaje/epigenomeviz_cache\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [15 x i8] c"ERROR: %s (%d)\00"
@errno = global i32 0
@.str.6 = [8 x i8] c"%d.json\00"
@str = [31 x i8] c"Content-Type:application/text\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
%4 = tail call i32 @time(i32 0)
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (...) @rand()
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%8 = bitcast i8** %1 to i8*
%9 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
store i8* %9, i8** %1
%10 = bitcast i64* %2 to i8*
store i64 1, i64* %2
%11 = load i32, i32* @stdin
%12 = call i32 @getline(i8** %1, i64* %2, i32 %11)
%13 = load i8*, i8** %1
%14 = call i8* @strdup(i8* %13)
%15 = bitcast i8** %3 to i8*
%16 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %0
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = load i32, i32* @errno
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %22, i32 %23)
br label %29
25: ; preds = %0
%26 = call i32 @fputs(i8* %14, i32* %18)
%27 = call i32 @fclose(i32* %18)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %6)
br label %29
29: ; preds = %25, %20
ret i32 1
}