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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int perror(char const *);
int /*<<< orphan*/ sleep(int);
scalar_t__ stat(char const *, struct stat *);
char *tpipe_name(char);
int c_main() {
  struct stat buf;
  FILE *f;
  const char *cnm = tpipe_name('C');
  if (stat(cnm, &buf) < 0 || !(f = fopen(cnm, "a")))
    return perror(cnm), sleep(3), 1;
  fprintf(f, "_c/proc/%d/fd/1\n", getpid());
  fclose(f);
  while (1)
    sleep(60);
}


x86 assembly (clang, -O0):
<c_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x43,%edi
call   1040 <tpipe_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jl     11cb <c_main+0x4b>
mov    -0x18(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e9 <c_main+0x69>
mov    -0x18(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10a0 <sleep@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xdfd(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
jmp    1213 <c_main+0x93>

x86 assembly (clang, -O2):
<c_main>:
push   %r14
push   %rbx
push   %rax
mov    $0x43,%edi
call   1040 <tpipe_name@plt>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rax,%rdi
call   1070 <stat@plt>
test   %rax,%rax
js     11ec <c_main+0x6c>
lea    0xe58(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ec <c_main+0x6c>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
nopl   0x0(%rax,%rax,1)
mov    $0x3c,%edi
call   10a0 <sleep@plt>
jmp    11e0 <c_main+0x60>
mov    %r14,%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10a0 <sleep@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"a\00"
@.str.1 = [17 x i8] c"_c/proc/%d/fd/1\0A\00"
define i32 @c_main() {
%1 = alloca %struct.stat
%2 = alloca i32*
%3 = alloca i8*
%4 = call i8* @tpipe_name(i8 signext 67)
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @stat(i8* %5, %struct.stat* %1)
%7 = icmp slt i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %2
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %8, %0
%13 = load i8*, i8** %3
%14 = call i32 @perror(i8* %13)
%15 = call i32 @sleep(i32 3)
ret i32 1
16: ; preds = %8
%17 = load i32*, i32** %2
%18 = call i32 (...) @getpid()
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %16, %22
%23 = call i32 @sleep(i32 60)
br label %22
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"a\00"
@.str.1 = [17 x i8] c"_c/proc/%d/fd/1\0A\00"
define i32 @c_main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i8* @tpipe_name(i8 signext 67)
%4 = call i64 @stat(i8* %3, %struct.stat* %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6, %0
%10 = call i32 @perror(i8* %3)
%11 = call i32 @sleep(i32 3)
ret i32 1
12: ; preds = %6
%13 = call i32 (...) @getpid()
%14 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @fclose(i32* %7)
br label %16
16: ; preds = %16, %12
%17 = call i32 @sleep(i32 60)
br label %16
}