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

/* Variables and functions */
int MAXPATHLEN;
int O_APPEND;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ STDOUT_FILENO;
int S_IRUSR;
int S_IWUSR;
int dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ lseek(int, long, int /*<<< orphan*/);
int open(char const *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlcat(char *, char *, int);
int /*<<< orphan*/ strlcpy(char *, char const *, int);
void dofile(void) {
  int fd;
  char path[MAXPATHLEN];
  const char *p;
  p = "nohup.out";
  if ((fd = open(p, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) >= 0)
    goto dupit;
  if ((p = getenv("HOME")) != NULL) {
    (void)strlcpy(path, p, sizeof(path));
    (void)strlcat(path, "/", sizeof(path));
    (void)strlcat(path, "nohup.out", sizeof(path));
    if ((fd = open(p = path, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) >=
        0)
      goto dupit;
  }
  (void)fprintf(stderr, "nohup: can't open a nohup.out file.\n");
  exit(127);
dupit:
  (void)lseek(fd, 0L, SEEK_END);
  if (dup2(fd, STDOUT_FILENO) == -1) {
    (void)fprintf(stderr, "nohup: %s\n", strerror(errno));
    exit(127);
  }
  (void)fprintf(stderr, "sending output to %s\n", p);
}


x86 assembly (clang, -O0):
<dofile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xe31(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
or     (%rax),%esi
mov    0x2da0(%rip),%rax
or     (%rax),%esi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
mov    0x2dbe(%rip),%rax
or     (%rax),%edx
call   1090 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jl     121a <dofile+0x8a>
jmp    12e4 <dofile+0x154>
lea    0xde9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12c3 <dofile+0x133>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1080 <strlcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%edx
lea    0xdb7(%rip),%rsi
call   1040 <strlcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%edx
lea    0xd92(%rip),%rsi
call   1040 <strlcat@plt>
mov    -0x28(%rbp),%rdi
mov    %rdi,-0x20(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
mov    0x2d6d(%rip),%rax
or     (%rax),%esi
mov    0x2cfc(%rip),%rax
or     (%rax),%esi
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
mov    0x2d1a(%rip),%rax
or     (%rax),%edx
call   1090 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jl     12be <dofile+0x12e>
jmp    12e4 <dofile+0x154>
jmp    12c3 <dofile+0x133>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x7f,%edi
call   10a0 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2ce2(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <lseek@plt>
mov    -0x4(%rbp),%edi
mov    0x2ce5(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    134b <dofile+0x1bb>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xcfc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x7f,%edi
call   10a0 <exit@plt>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xce2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dofile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e23(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e18(%rip),%rax
mov    0x2e31(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dbe(%rip),%rax
or     (%rax),%esi
mov    0x2dc5(%rip),%rax
mov    0x2dde(%rip),%r13
mov    0x0(%r13),%edx
or     (%rax),%edx
lea    0xe11(%rip),%r15
mov    %r15,%rdi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1281 <dofile+0xf1>
lea    0xe02(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12fe <dofile+0x16e>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   1080 <strlcpy@plt>
lea    0xde4(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
call   1040 <strlcat@plt>
lea    0xdc3(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
call   1040 <strlcat@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
mov    0x2d80(%rip),%rax
or     (%rax),%esi
mov    0x2d2f(%rip),%rax
or     (%rax),%esi
mov    0x0(%r13),%edx
mov    0x2d32(%rip),%rax
or     (%rax),%edx
mov    %r12,%rdi
call   1090 <open@plt>
mov    %eax,%ebx
mov    %r12,%r15
test   %eax,%eax
js     12fe <dofile+0x16e>
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <dup2@plt>
mov    0x2d06(%rip),%rcx
mov    (%rcx),%ebx
cmp    $0xffffffff,%eax
je     12d3 <dofile+0x143>
lea    0xd89(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd4e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x7f,%edi
call   10a0 <exit@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xd03(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x7f,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [10 x i8] c"nohup.out\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.3 = [37 x i8] c"nohup: can't open a nohup.out file.\0A\00"
@SEEK_END = global i32 0
@STDOUT_FILENO = global i32 0
@.str.4 = [11 x i8] c"nohup: %s\0A\00"
@errno = global i32 0
@.str.5 = [22 x i8] c"sending output to %s\0A\00"
define void @dofile() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %4
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_APPEND
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %9, i32 %14, i32 %17)
store i32 %18, i32* %1
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %0
br label %48
21: ; preds = %0
%22 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %44
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = trunc i64 %6 to i32
%27 = call i32 @strlcpy(i8* %8, i8* %25, i32 %26)
%28 = trunc i64 %6 to i32
%29 = call i32 @strlcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = trunc i64 %6 to i32
%31 = call i32 @strlcat(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %30)
store i8* %8, i8** %4
%32 = load i32, i32* @O_RDWR
%33 = load i32, i32* @O_CREAT
%34 = or i32 %32, %33
%35 = load i32, i32* @O_APPEND
%36 = or i32 %34, %35
%37 = load i32, i32* @S_IRUSR
%38 = load i32, i32* @S_IWUSR
%39 = or i32 %37, %38
%40 = call i32 @open(i8* %8, i32 %36, i32 %39)
store i32 %40, i32* %1
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %24
br label %48
43: ; preds = %24
br label %44
44: ; preds = %43, %21
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 127)
unreachable
48: ; preds = %42, %20
%49 = load i32, i32* %1
%50 = load i32, i32* @SEEK_END
%51 = call i32 @lseek(i32 %49, i64 0, i32 %50)
%52 = load i32, i32* %1
%53 = load i32, i32* @STDOUT_FILENO
%54 = call i32 @dup2(i32 %52, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %62
56: ; preds = %48
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = call i32 @exit(i32 127)
unreachable
62: ; preds = %48
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %4
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %64)
%66 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [10 x i8] c"nohup.out\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.3 = [37 x i8] c"nohup: can't open a nohup.out file.\0A\00"
@SEEK_END = global i32 0
@STDOUT_FILENO = global i32 0
@.str.4 = [11 x i8] c"nohup: %s\0A\00"
@errno = global i32 0
@.str.5 = [22 x i8] c"sending output to %s\0A\00"
define void @dofile() {
%1 = load i32, i32* @MAXPATHLEN
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_APPEND
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %35, label %14
14: ; preds = %0
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %31, label %17
17: ; preds = %14
%18 = call i32 @strlcpy(i8* %3, i8* %15, i32 %1)
%19 = call i32 @strlcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%20 = call i32 @strlcat(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%21 = load i32, i32* @O_RDWR
%22 = load i32, i32* @O_CREAT
%23 = or i32 %22, %21
%24 = load i32, i32* @O_APPEND
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %27, %26
%29 = call i32 @open(i8* %3, i32 %25, i32 %28)
%30 = icmp sgt i32 %29, -1
br i1 %30, label %35, label %31
31: ; preds = %17, %14
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 127)
unreachable
35: ; preds = %17, %0
%36 = phi i32 [ %12, %0 ], [ %29, %17 ]
%37 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %0 ], [ %3, %17 ]
%38 = load i32, i32* @SEEK_END
%39 = call i32 @lseek(i32 %36, i64 0, i32 %38)
%40 = load i32, i32* @STDOUT_FILENO
%41 = call i32 @dup2(i32 %36, i32 %40)
%42 = icmp eq i32 %41, -1
%43 = load i32, i32* @stderr
br i1 %42, label %44, label %49
44: ; preds = %35
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 127)
unreachable
49: ; preds = %35
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %37)
ret void
}