#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ stat(char const *, struct stat *);
int json_file_read(char const *json_file_path, char **json_out) {
  int success;
  struct stat file_stats;
  FILE *json_file;
  size_t bytes_read;
  json_file = NULL;
  *json_out = NULL;
  success = (0 == stat(json_file_path, &file_stats));
  if (success) {
    json_file = fopen(("issues.json"), "r");
    success = (NULL != json_file);
  }
  if (success) {
    *json_out = calloc(file_stats.st_size + 1, 1);
    success = (NULL != *json_out);
  }
  if (success) {
    bytes_read = fread(*json_out, 1, file_stats.st_size, json_file);
    success = (bytes_read == file_stats.st_size);
  }
  if (!success) {
    free(*json_out);
    *json_out = NULL;
  }
  fclose(json_file);
  return success;
}


x86 assembly (clang, -O0):
<json_file_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d5 <json_file_read+0x75>
lea    0xe4c(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     120d <json_file_read+0xad>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1249 <json_file_read+0xe9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    126a <json_file_read+0x10a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<json_file_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
movq   $0x0,(%rsi)
mov    %rsp,%rsi
call   1070 <stat@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11a7 <json_file_read+0x47>
mov    (%rbx),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
xor    %ebp,%ebp
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe52(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ff <json_file_read+0x9f>
mov    %rax,%r14
mov    (%rsp),%r15d
lea    0x1(%r15),%edi
mov    $0x1,%ebp
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1181 <json_file_read+0x21>
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movslq (%rsp),%rcx
cmp    %rcx,%rax
jne    1181 <json_file_read+0x21>
jmp    1192 <json_file_read+0x32>
xor    %r14d,%r14d
jmp    1181 <json_file_read+0x21>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [12 x i8] c"issues.json\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @json_file_read(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32* null, i32** %7
%9 = load i8**, i8*** %4
store i8* null, i8** %9
%10 = load i8*, i8** %3
%11 = call i64 @stat(i8* %10, %struct.stat* %6)
%12 = icmp eq i64 0, %11
%13 = zext i1 %12 to i32
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp ne i32* null, %18
%20 = zext i1 %19 to i32
store i32 %20, i32* %5
br label %21
21: ; preds = %16, %2
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
%28 = call i8* @calloc(i32 %27, i32 1)
%29 = load i8**, i8*** %4
store i8* %28, i8** %29
%30 = load i8**, i8*** %4
%31 = load i8*, i8** %30
%32 = icmp ne i8* null, %31
%33 = zext i1 %32 to i32
store i32 %33, i32* %5
br label %34
34: ; preds = %24, %21
%35 = load i32, i32* %5
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %50
37: ; preds = %34
%38 = load i8**, i8*** %4
%39 = load i8*, i8** %38
%40 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load i32*, i32** %7
%43 = call i64 @fread(i8* %39, i32 1, i32 %41, i32* %42)
store i64 %43, i64* %8
%44 = load i64, i64* %8
%45 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = icmp eq i64 %44, %47
%49 = zext i1 %48 to i32
store i32 %49, i32* %5
br label %50
50: ; preds = %37, %34
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %50
%54 = load i8**, i8*** %4
%55 = load i8*, i8** %54
%56 = call i32 @free(i8* %55)
%57 = load i8**, i8*** %4
store i8* null, i8** %57
br label %58
58: ; preds = %53, %50
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [12 x i8] c"issues.json\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @json_file_read(i8* %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
store i8* null, i8** %1
%5 = call i64 @stat(i8* %0, %struct.stat* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %21, label %10
10: ; preds = %7
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = call i8* @calloc(i32 %13, i32 1)
store i8* %14, i8** %1
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = call i64 @fread(i8* %14, i32 1, i32 %12, i32* %8)
%18 = load i32, i32* %11
%19 = sext i32 %18 to i64
%20 = icmp eq i64 %17, %19
br i1 %20, label %25, label %21
21: ; preds = %2, %7, %10, %16
%22 = phi i32* [ %8, %16 ], [ null, %7 ], [ %8, %10 ], [ null, %2 ]
%23 = load i8*, i8** %1
%24 = call i32 @free(i8* %23)
store i8* null, i8** %1
br label %25
25: ; preds = %21, %16
%26 = phi i32 [ 0, %21 ], [ 1, %16 ]
%27 = phi i32* [ %22, %21 ], [ %8, %16 ]
%28 = call i32 @fclose(i32* %27)
ret i32 %26
}