#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_mode;
  scalar_t__ st_size;
};
typedef scalar_t__ off_t;
typedef int mode_t;
typedef int /*<<< orphan*/ intmax_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int);
void print_file_sz(FILE *fptr) {
  int fd;
  struct stat sb;
  off_t fsize;
  mode_t fmode;
  fd = fileno(fptr);
  fstat(fd, &sb);
  fsize = sb.st_size;
  fmode = sb.st_mode;
  printf("file size: %jd bytes, mode: (%3o)\n", (intmax_t)fsize, fmode & 0777);
}


x86 assembly (clang, -O0):
<print_file_sz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <fstat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x2c(%rbp),%edx
and    $0x1ff,%edx
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file_sz>:
sub    $0x18,%rsp
call   1040 <fileno@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1050 <fstat@plt>
mov    0x10(%rsp),%esi
mov    $0x1ff,%edx
and    0x8(%rsp),%edx
lea    0xea7(%rip),%rdi
add    $0x18,%rsp
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@.str = [35 x i8] c"file size: %jd bytes, mode: (%3o)\0A\00"
define void @print_file_sz(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @fileno(i32* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32 @fstat(i32 %9, %struct.stat* %4)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%12 = load i64, i64* %11
store i64 %12, i64* %5
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %6
%15 = load i64, i64* %5
%16 = trunc i64 %15 to i32
%17 = load i32, i32* %6
%18 = and i32 %17, 511
%19 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@.str = [35 x i8] c"file size: %jd bytes, mode: (%3o)\0A\00"
define void @print_file_sz(i32* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32 @fileno(i32* %0)
%5 = call i32 @fstat(i32 %4, %struct.stat* %2)
%6 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%9 = load i32, i32* %8
%10 = trunc i64 %7 to i32
%11 = and i32 %9, 511
%12 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
ret void
}