#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_mode;
};
typedef scalar_t__ mode_t;

/* Variables and functions */
int creat(char *, int);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  struct stat stbf1;
  int n;
  if ((n = creat("dir", 040777)) != -1) {
    if (fstat(n, &stbf1) != 0)
      printf("fstat problem\n");
    else if (stbf1.st_mode != (mode_t)0100777)
      printf("mode=%d\n", stbf1.st_mode);
  }
}


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)
lea    0xeb3(%rip),%rdi
mov    $0x41ff,%esi
call   1040 <creat@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11b6 <main+0x86>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%rax
je     118c <main+0x5c>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <main+0x81>
cmpq   $0x81ff,-0x18(%rbp)
je     11ac <main+0x7c>
mov    -0x18(%rbp),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <main+0x81>
jmp    11b6 <main+0x86>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
mov    $0x41ff,%esi
call   1050 <creat@plt>
cmp    $0xffffffff,%eax
je     118f <main+0x4f>
mov    %rsp,%rsi
mov    %eax,%edi
call   1060 <fstat@plt>
test   %rax,%rax
je     1174 <main+0x34>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
jmp    118f <main+0x4f>
mov    (%rsp),%rsi
cmp    $0x81ff,%rsi
je     118f <main+0x4f>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [4 x i8] c"dir\00"
@.str.1 = [15 x i8] c"fstat problem\0A\00"
@.str.2 = [9 x i8] c"mode=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 16895)
store i32 %8, i32* %7
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = load i32, i32* %7
%12 = call i64 @fstat(i32 %11, %struct.stat* %6)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %25
16: ; preds = %10
%17 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%18 = load i64, i64* %17
%19 = icmp ne i64 %18, 33279
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%22 = load i64, i64* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %24
24: ; preds = %20, %16
br label %25
25: ; preds = %24, %14
br label %26
26: ; preds = %25, %2
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [4 x i8] c"dir\00"
@.str.2 = [9 x i8] c"mode=%d\0A\00"
@str = [14 x i8] c"fstat problem\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @creat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 16895)
%6 = icmp eq i32 %5, -1
br i1 %6, label %18, label %7
7: ; preds = %2
%8 = call i64 @fstat(i32 %5, %struct.stat* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %18
12: ; preds = %7
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, 33279
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 %14)
br label %18
18: ; preds = %10, %16, %12, %2
ret i32 0
}