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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int daemon(int, int);
int execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(void) {
  FILE *err = freopen("stderr.txt", "w", stderr);
  int rc = daemon(1, 1);
  if (rc) {
    perror("failed to daemonize");
    return EXIT_FAILURE;
  }
  pid_t pid = fork();
  if (pid == 0) {
    rc = execlp("/usr/bin/python", "/usr/bin/python",
                "/home/miky/Documentos/repos/Weblabs.py/code.py", NULL);
    if (rc) {
      perror("failed to exec python");
      return EXIT_FAILURE;
    }
  } else {
    waitpid(pid, NULL, 0);
  }
  fclose(err);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
lea    0xe71(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1040 <freopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1050 <daemon@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d5 <main+0x65>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <main+0xe8>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1234 <main+0xc4>
lea    0xe2f(%rip),%rsi
lea    0xe38(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     122f <main+0xbf>
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <main+0xe8>
jmp    1243 <main+0xd3>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
lea    0xe7f(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1040 <freopen@plt>
mov    %rax,%rbx
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <daemon@plt>
test   %eax,%eax
jne    11ec <main+0x7c>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11bd <main+0x4d>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
jmp    11d9 <main+0x69>
lea    0xe5d(%rip),%rdi
lea    0xe66(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1080 <execlp@plt>
test   %eax,%eax
jne    11f5 <main+0x85>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xe1a(%rip),%rdi
jmp    11fc <main+0x8c>
lea    0xe64(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dd0(%rip),%rax
jmp    11e8 <main+0x78>

LLVM IR (-O0):
@.str = [11 x i8] c"stderr.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"failed to daemonize\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [16 x i8] c"/usr/bin/python\00"
@.str.4 = [47 x i8] c"/home/miky/Documentos/repos/Weblabs.py/code.py\00"
@.str.5 = [22 x i8] c"failed to exec python\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = load i32, i32* @stderr
%6 = call i32* @freopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %5)
store i32* %6, i32** %2
%7 = call i32 @daemon(i32 1, i32 1)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %1
br label %32
13: ; preds = %0
%14 = call i64 (...) @fork()
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = call i32 @execlp(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i32* null)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
store i32 %23, i32* %1
br label %32
24: ; preds = %17
br label %28
25: ; preds = %13
%26 = load i64, i64* %4
%27 = call i32 @waitpid(i64 %26, i32* null, i32 0)
br label %28
28: ; preds = %25, %24
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
%31 = load i32, i32* @EXIT_SUCCESS
store i32 %31, i32* %1
br label %32
32: ; preds = %28, %21, %10
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [11 x i8] c"stderr.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"failed to daemonize\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [16 x i8] c"/usr/bin/python\00"
@.str.4 = [47 x i8] c"/home/miky/Documentos/repos/Weblabs.py/code.py\00"
@.str.5 = [22 x i8] c"failed to exec python\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @stderr
%2 = tail call i32* @freopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = tail call i32 @daemon(i32 1, i32 1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %19
7: ; preds = %0
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = tail call i32 @execlp(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i32* null)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %19
15: ; preds = %7
%16 = tail call i32 @waitpid(i64 %8, i32* null, i32 0)
br label %17
17: ; preds = %10, %15
%18 = tail call i32 @fclose(i32* %2)
br label %19
19: ; preds = %13, %17, %5
%20 = phi i32* [ @EXIT_FAILURE, %5 ], [ @EXIT_FAILURE, %13 ], [ @EXIT_SUCCESS, %17 ]
%21 = load i32, i32* %20
ret i32 %21
}