#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 {
  scalar_t__ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
int stat(char *, struct stat *);
char *string_f90_to_c(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_file_size_c_(char *name, long len_name) {
  long size;
  char namebuff[257];
  char *fname;
  int stat_error_flag;
  struct stat stbuf;
  strncpy(namebuff, name, 257 - 1);
  if (len_name >= 257) {
    return -1;
  }
  namebuff[257 - 1] = '\0';
  fname = string_f90_to_c(namebuff);
  if (fname == (char *)0) {
    printf("string_f90_to_c returned with an error\n");
    return -1;
  }
  size = -1;
  stat_error_flag = stat(fname, &stbuf);
  if (stat_error_flag == 0) {
    size = (long)stbuf.st_size;
  }
  free(fname);
  return size;
}


x86 assembly (clang, -O0):
<get_file_size_c_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1040 <strncpy@plt>
cmpq   $0x101,-0x18(%rbp)
jl     1192 <get_file_size_c_+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    121b <get_file_size_c_+0xcb>
movb   $0x0,-0x30(%rbp)
lea    -0x130(%rbp),%rdi
call   1060 <string_f90_to_c@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    11cf <get_file_size_c_+0x7f>
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121b <get_file_size_c_+0xcb>
movq   $0xffffffffffffffff,-0x20(%rbp)
ff
mov    -0x138(%rbp),%rdi
lea    -0x148(%rbp),%rsi
call   1070 <stat@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x0,-0x13c(%rbp)
jne    1208 <get_file_size_c_+0xb8>
mov    -0x148(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x138(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size_c_>:
push   %rbp
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0x10(%rsp),%rdi
mov    $0x100,%edx
call   1040 <strncpy@plt>
mov    $0xffffffff,%ebp
cmp    $0x100,%rbx
jg     11c3 <get_file_size_c_+0x73>
movb   $0x0,0x110(%rsp)
lea    0x10(%rsp),%rdi
call   1060 <string_f90_to_c@plt>
test   %rax,%rax
je     11b7 <get_file_size_c_+0x67>
mov    %rax,%r14
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1070 <stat@plt>
neg    %eax
sbb    %ebp,%ebp
or     0x8(%rsp),%ebp
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11c3 <get_file_size_c_+0x73>
lea    0xe42(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [40 x i8] c"string_f90_to_c returned with an error\0A\00"
define i32 @get_file_size_c_(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca [257 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.stat
store i8* %0, i8** %4
store i64 %1, i64* %5
%11 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32 @strncpy(i8* %11, i8* %12, i32 256)
%14 = load i64, i64* %5
%15 = icmp sge i64 %14, 257
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %38
17: ; preds = %2
%18 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 256
store i8 0, i8* %18
%19 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%20 = call i8* @string_f90_to_c(i8* %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
25: ; preds = %17
store i64 -1, i64* %6
%26 = load i8*, i8** %8
%27 = call i32 @stat(i8* %26, %struct.stat* %10)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%32 = load i64, i64* %31
store i64 %32, i64* %6
br label %33
33: ; preds = %30, %25
%34 = load i8*, i8** %8
%35 = call i32 @free(i8* %34)
%36 = load i64, i64* %6
%37 = trunc i64 %36 to i32
store i32 %37, i32* %3
br label %38
38: ; preds = %33, %23, %16
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@str = [39 x i8] c"string_f90_to_c returned with an error\00"
define i32 @get_file_size_c_(i8* %0, i64 %1) {
%3 = alloca [257 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @strncpy(i8* %5, i8* %0, i32 256)
%8 = icmp sgt i64 %1, 256
br i1 %8, label %23, label %9
9: ; preds = %2
%10 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 256
store i8 0, i8* %10
%11 = call i8* @string_f90_to_c(i8* %5)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %23
15: ; preds = %9
%16 = call i32 @stat(i8* %11, %struct.stat* %4)
%17 = icmp eq i32 %16, 0
%18 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = select i1 %17, i32 %20, i32 -1
%22 = call i32 @free(i8* %11)
br label %23
23: ; preds = %2, %15, %13
%24 = phi i32 [ -1, %13 ], [ %21, %15 ], [ -1, %2 ]
ret i32 %24
}