#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*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  const char *tag = (argc > 1 ? argv[1] : "xxx");
  FILE *stdout2 = fdopen(3, "w");
  if (stdout2 == NULL)
    exit(1);
  if (ferror(stdout) || fclose(stdout) || ferror(stdout2) || fclose(stdout2))
    exit(1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1171 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1181 <main+0x41>
lea    0xe88(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1181 <main+0x41>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x3,%edi
lea    0xe6f(%rip),%rsi
call   1050 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b3 <main+0x73>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    120b <main+0xcb>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
jne    120b <main+0xcb>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    120b <main+0xcb>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1215 <main+0xd5>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
mov    $0x3,%edi
call   1050 <fdopen@plt>
test   %rax,%rax
je     11a2 <main+0x62>
mov    %rax,%rbx
mov    0x2e7c(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11a2 <main+0x62>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    11a2 <main+0x62>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11a2 <main+0x62>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    11a2 <main+0x62>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"xxx\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
br label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %10
%16 = phi i8* [ %13, %10 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %14 ]
store i8* %16, i8** %6
%17 = call i32* @fdopen(i32 3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = load i32*, i32** @stdout
%24 = call i64 @ferror(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %22
%27 = load i32*, i32** @stdout
%28 = call i64 @fclose(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %26
%31 = load i32*, i32** %7
%32 = call i64 @ferror(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i32*, i32** %7
%36 = call i64 @fclose(i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34, %30, %26, %22
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %34
%41 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fdopen(i32 3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = load i32*, i32** @stdout
%9 = tail call i64 @ferror(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = tail call i64 @fclose(i32* %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = tail call i64 @ferror(i32* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i64 @fclose(i32* %3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17, %14, %11, %7
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %17
%23 = tail call i32 @exit(i32 0)
unreachable
}