#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
void my_fscanf(char *path) {
  FILE *fp = NULL;
  fp = fopen(path, "r+");
  if (fp == NULL) {
    perror("my_fprintf fopen");
    return;
  }
  int a = 0;
  int b = 0;
  int c = 0;
  fscanf(fp, "%d %d %d\n", &a, &b, &c);
  printf("a = %d, b = %d, c = %d\n", a, b, c);
  if (fp != NULL) {
    fclose(fp);
    fp = NULL;
  }
}


x86 assembly (clang, -O0):
<my_fscanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <my_fscanf+0x44>
lea    0xe79(%rip),%rdi
call   1070 <perror@plt>
jmp    11f6 <my_fscanf+0xa6>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe60(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1050 <fscanf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11f6 <my_fscanf+0xa6>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x10(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_fscanf>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c5 <my_fscanf+0x75>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xe8c(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe37(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [17 x i8] c"my_fprintf fopen\00"
@.str.2 = [10 x i8] c"%d %d %d\0A\00"
@.str.3 = [24 x i8] c"a = %d, b = %d, c = %d\0A\00"
define void @my_fscanf(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32* null, i32** %3
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %25
13: ; preds = %1
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%14 = load i32*, i32** %3
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = load i32*, i32** %3
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
store i32* null, i32** %3
br label %25
25: ; preds = %11, %22, %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [17 x i8] c"my_fprintf fopen\00"
@.str.2 = [10 x i8] c"%d %d %d\0A\00"
@.str.3 = [24 x i8] c"a = %d, b = %d, c = %d\0A\00"
define void @my_fscanf(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %19
9: ; preds = %1
%10 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%11 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%12 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%13 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
%18 = call i32 @fclose(i32* %5)
br label %19
19: ; preds = %9, %7
ret void
}