#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;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, int *, int);
scalar_t__ stat(char *, struct stat *);
void print_inc_file() {
  int fd, fintt;
  int *fint = &fintt;
  struct stat stbuf;
  if (stat("test_inc", &stbuf))
    return;
  fd = open("test_inc", O_RDONLY, 0666);
  if (fd < 0) {
    perror("open");
    return;
  }
  read(fd, fint, sizeof(int));
  close(fd);
  printf("fint = %d\n", *fint);
}


x86 assembly (clang, -O0):
<print_inc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xe89(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
je     118f <print_inc_file+0x2f>
jmp    11f2 <print_inc_file+0x92>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11c7 <print_inc_file+0x67>
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
jmp    11f2 <print_inc_file+0x92>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_inc_file>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
jne    11c3 <print_inc_file+0x63>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11c9 <print_inc_file+0x69>
mov    %eax,%ebx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x4(%rsp),%esi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe39(%rip),%rdi
call   1080 <perror@plt>
jmp    11c3 <print_inc_file+0x63>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"test_inc\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [11 x i8] c"fint = %d\0A\00"
define void @print_inc_file() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.stat
store i32* %2, i32** %3
%5 = call i64 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
br label %24
8: ; preds = %0
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9, i32 438)
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %24
15: ; preds = %8
%16 = load i32, i32* %1
%17 = load i32*, i32** %3
%18 = call i32 @read(i32 %16, i32* %17, i32 4)
%19 = load i32, i32* %1
%20 = call i32 @close(i32 %19)
%21 = load i32*, i32** %3
%22 = load i32, i32* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %15, %13, %7
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"test_inc\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [11 x i8] c"fint = %d\0A\00"
define void @print_inc_file() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.stat* %2 to i8*
%5 = call i64 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %0
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8, i32 438)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
13: ; preds = %7
%14 = call i32 @read(i32 %9, i32* %1, i32 4)
%15 = call i32 @close(i32 %9)
%16 = load i32, i32* %1
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %0, %13, %11
ret void
}