#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);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  FILE *fileid;
  system("tty > .Btty");
  fileid = fopen(".Bxok", "w");
  if (fileid == NULL) {
    printf("\n  Can't open \".Bxok\" for writing\n");
    exit(1);
  }
  fclose(fileid);
  while (1)
    sleep(1000000);
}


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    0xe83(%rip),%rdi
call   1040 <system@plt>
lea    0xe83(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <main+0x5a>
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xf4240,%edi
call   1080 <sleep@plt>
jmp    11c3 <main+0x63>

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xe98(%rip),%rdi
call   1050 <system@plt>
lea    0xe98(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119c <main+0x3c>
mov    %rax,%rdi
call   1040 <fclose@plt>
nopl   (%rax)
mov    $0xf4240,%edi
call   1080 <sleep@plt>
jmp    1190 <main+0x30>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"tty > .Btty\00"
@.str.1 = [6 x i8] c".Bxok\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [35 x i8] c"\0A Can't open \22.Bxok\22 for writing\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %14, %17
%18 = call i32 @sleep(i32 1000000)
br label %17
}

LLVM IR (-O2):
@.str = [12 x i8] c"tty > .Btty\00"
@.str.1 = [6 x i8] c".Bxok\00"
@.str.2 = [2 x i8] c"w\00"
@str = [34 x i8] c"\0A Can't open \22.Bxok\22 for writing\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32 @fclose(i32* %4)
br label %11
11: ; preds = %11, %9
%12 = tail call i32 @sleep(i32 1000000)
br label %11
}