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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ fwrite(char const *, int, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ perr(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strlen(char const *);
int main(void) {
  FILE *f;
  int fd;
  const char fname[] = "sk1test.dat";
  const char tsttxt1[] = "This is the first line of this test.\n";
  char buf[sizeof(tsttxt1)] = "";
  f = fdopen(1, "w");
  if (f == NULL || fwrite(tsttxt1, 1, strlen(tsttxt1), f) != strlen(tsttxt1))
    perr("fdopen or fwrite");
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe65(%rip),%eax
mov    %eax,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x26,%edx
call   1070 <memcpy@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x26,%edx
call   1060 <memset@plt>
mov    $0x1,%edi
lea    0xe35(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123a <main+0xba>
lea    -0x50(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x90(%rbp),%rdi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %rax,-0x88(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
cmp    %rcx,%rax
je     1246 <main+0xc6>
lea    0xdcd(%rip),%rdi
call   1050 <perr@plt>
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xea2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe86(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0xa2e7473657420,%rax
mov    %rax,0x1e(%rsp)
lea    0xe92(%rip),%rsi
mov    $0x1,%edi
call   1060 <fdopen@plt>
test   %rax,%rax
je     11d4 <main+0x74>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
je     11e0 <main+0x80>
lea    0xe4d(%rip),%rdi
call   1050 <perr@plt>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.main.fname = [12 x i8] c"sk1test.dat\00"
@__const.main.tsttxt1 = [38 x i8] c"This is the first line of this test.\0A\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [17 x i8] c"fdopen or fwrite\00"
@.str.2 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [12 x i8]
%5 = alloca [38 x i8]
%6 = alloca [38 x i8]
store i32 0, i32* %1
%7 = bitcast [12 x i8]* %4 to i8*
%8 = bitcast [38 x i8]* %5 to i8*
%9 = bitcast [38 x i8]* %6 to i8*
%10 = call i32* @fdopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %22, label %13
13: ; preds = %0
%14 = getelementptr inbounds [38 x i8], [38 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [38 x i8], [38 x i8]* %5, i64 0, i64 0
%16 = call i64 @strlen(i8* %15)
%17 = load i32*, i32** %2
%18 = call i64 @fwrite(i8* %14, i32 1, i64 %16, i32* %17)
%19 = getelementptr inbounds [38 x i8], [38 x i8]* %5, i64 0, i64 0
%20 = call i64 @strlen(i8* %19)
%21 = icmp ne i64 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %13, %0
%23 = call i32 @perr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %13
%25 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.tsttxt1 = [38 x i8] c"This is the first line of this test.\0A\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [17 x i8] c"fdopen or fwrite\00"
@str = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca [38 x i8]
%2 = getelementptr inbounds [38 x i8], [38 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fdopen(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = call i64 @strlen(i8* %2)
%7 = call i64 @fwrite(i8* %2, i32 1, i64 %6, i32* %3)
%8 = call i64 @strlen(i8* %2)
%9 = icmp eq i64 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %5, %0
%11 = tail call i32 @perr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
}