#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 */

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void ft_stdin_file(void) {
  int ret;
  char c;
  int fd;
  fd = open("temp", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  if (fd == -1)
    return;
  while ((ret = read(0, &c, 1))) {
    if (ret == -1)
      break;
    write(fd, &c, 1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<ft_stdin_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2ea0(%rip),%rax
or     (%rax),%esi
mov    0x2e8f(%rip),%rax
or     (%rax),%esi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    0x2e65(%rip),%rax
or     (%rax),%edx
lea    0xe84(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1193 <ft_stdin_file+0x53>
jmp    11e1 <ft_stdin_file+0xa1>
jmp    1198 <ft_stdin_file+0x58>
xor    %edi,%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     11d9 <ft_stdin_file+0x99>
cmpl   $0xffffffff,-0x4(%rbp)
jne    11c3 <ft_stdin_file+0x83>
jmp    11d9 <ft_stdin_file+0x99>
mov    -0xc(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1198 <ft_stdin_file+0x58>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_stdin_file>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e6e(%rip),%rax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e94(%rip),%rax
or     (%rax),%esi
mov    0x2e63(%rip),%rax
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe89(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11e3 <ft_stdin_file+0xa3>
mov    %eax,%ebp
lea    0x7(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
add    $0x1,%eax
cmp    $0x2,%eax
jb     11d6 <ft_stdin_file+0x96>
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
add    $0x1,%eax
cmp    $0x1,%eax
ja     11b0 <ft_stdin_file+0x70>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"temp\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define void @ft_stdin_file() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %0
br label %30
16: ; preds = %0
br label %17
17: ; preds = %24, %16
%18 = call i32 @read(i32 0, i8* %2, i32 1)
store i32 %18, i32* %1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %20
br label %27
24: ; preds = %20
%25 = load i32, i32* %3
%26 = call i32 @write(i32 %25, i8* %2, i32 1)
br label %17
27: ; preds = %23, %17
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27, %15
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"temp\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define void @ft_stdin_file() {
%1 = alloca i8
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %23, label %12
12: ; preds = %0
%13 = call i32 @read(i32 0, i8* %1, i32 1)
%14 = add i32 %13, 1
%15 = icmp ult i32 %14, 2
br i1 %15, label %21, label %16
16: ; preds = %12, %16
%17 = call i32 @write(i32 %10, i8* %1, i32 1)
%18 = call i32 @read(i32 0, i8* %1, i32 1)
%19 = add i32 %18, 1
%20 = icmp ult i32 %19, 2
br i1 %20, label %21, label %16
21: ; preds = %16, %12
%22 = tail call i32 @close(i32 %10)
br label %23
23: ; preds = %0, %21
ret void
}