#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 dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  if (argc > 2) {
    FILE *fp;
    int fd = 0;
    struct stat st;
    fp = fopen(argv[1], argv[2]);
    fd = fileno(fp);
    fstat(fd, &st);
  } else {
    printf("Please specify a file and operation\n\n");
    printf("Usage:\n");
    printf("fstat_test <filename> <operation>");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    119d <main+0x5d>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <fstat@plt>
jmp    11c1 <main+0x81>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x3,%edi
jl     1177 <main+0x27>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1060 <fopen@plt>
mov    %rax,%rdi
call   1050 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <fstat@plt>
jmp    119b <main+0x4b>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [38 x i8] c"Please specify a file and operation\0A\0A\00"
@.str.1 = [8 x i8] c"Usage:\0A\00"
@.str.2 = [34 x i8] c"fstat_test <filename> <operation>\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 2
br i1 %10, label %11, label %23
11: ; preds = %2
store i32 0, i32* %7
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %14, i8* %17)
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = call i32 @fileno(i32* %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = call i32 @fstat(i32 %21, %struct.stat* %8)
br label %27
23: ; preds = %2
%24 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %23, %11
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.2 = [34 x i8] c"fstat_test <filename> <operation>\00"
@str = [37 x i8] c"Please specify a file and operation\0A\00"
@str.3 = [7 x i8] c"Usage:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp sgt i32 %0, 2
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %8, i8* %10)
%12 = tail call i32 @fileno(i32* %11)
%13 = call i32 @fstat(i32 %12, %struct.stat* %3)
br label %18
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.3, i64 0, i64 0))
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %14, %5
ret i32 0
}