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

/* Variables and functions */
int dup2(int /*<<< orphan*/, int);
int /*<<< orphan*/ error(char *);
int execle(char *, char *, char *, char *, int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *phrase = argv[1];
  char *vars[] = {"RSS_FEED=http://rss.cnn.com/rss/edition.rss", NULL};
  FILE *f = fopen("stories.txt", "w");
  if (!f) {
    error("Can't open stories.txt");
  }
  pid_t pid = fork();
  if (pid == -1) {
    error("Can't fork process");
  }
  if (!pid) {
    if (dup2(fileno(f), 1) == -1) {
      error("Can't redirect Standard Output");
    }
    if (execle("/usr/bin/python", "/usr/bin/python", "./rssgossip.py", phrase,
               NULL, vars) == -1) {
      error("Can't run script");
    }
    int pid_status;
    if (waitpid(pid, &pid_status, 0) == -1) {
      error("Error waiting for child process");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2c77(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c74(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d6 <main+0x66>
lea    0xe5d(%rip),%rdi
call   1050 <error@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11f6 <main+0x86>
lea    0xe54(%rip),%rdi
call   1050 <error@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    128a <main+0x11a>
mov    -0x38(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    122a <main+0xba>
lea    0xe33(%rip),%rdi
call   1050 <error@plt>
mov    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%r9
lea    0xe3e(%rip),%rsi
lea    0xe47(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1080 <execle@plt>
cmp    $0xffffffff,%eax
jne    1262 <main+0xf2>
lea    0xe39(%rip),%rdi
call   1050 <error@plt>
mov    -0x3c(%rbp),%edi
lea    -0x40(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1285 <main+0x115>
lea    0xe27(%rip),%rdi
call   1050 <error@plt>
jmp    128a <main+0x11a>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%r14
movaps 0x2c8e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xeab(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ae <main+0x3e>
lea    0xe85(%rip),%rdi
call   1050 <error@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11c7 <main+0x57>
cmp    $0xffffffff,%eax
jne    123d <main+0xcd>
lea    0xe80(%rip),%rdi
jmp    1238 <main+0xc8>
mov    %rbx,%rdi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11ec <main+0x7c>
lea    0xe71(%rip),%rdi
call   1050 <error@plt>
lea    0xe84(%rip),%rdi
lea    0xe8d(%rip),%rdx
lea    0x10(%rsp),%r9
mov    %rdi,%rsi
mov    %r14,%rcx
xor    %r8d,%r8d
call   1080 <execle@plt>
cmp    $0xffffffff,%eax
jne    121e <main+0xae>
lea    0xe7d(%rip),%rdi
call   1050 <error@plt>
lea    0xc(%rsp),%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    123d <main+0xcd>
lea    0xe6f(%rip),%rdi
call   1050 <error@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [44 x i8] c"RSS_FEED=http://rss.cnn.com/rss/edition.rss\00"
@__const.main.vars = [2 x i8*] [i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [12 x i8] c"stories.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [23 x i8] c"Can't open stories.txt\00"
@.str.4 = [19 x i8] c"Can't fork process\00"
@.str.5 = [31 x i8] c"Can't redirect Standard Output\00"
@.str.6 = [16 x i8] c"/usr/bin/python\00"
@.str.7 = [15 x i8] c"./rssgossip.py\00"
@.str.8 = [17 x i8] c"Can't run script\00"
@.str.9 = [32 x i8] c"Error waiting for child process\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [2 x i8*]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = bitcast [2 x i8*]* %7 to i8*
%15 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %2
%19 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = call i32 (...) @fork()
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %50, label %29
29: ; preds = %26
%30 = load i32*, i32** %8
%31 = call i32 @fileno(i32* %30)
%32 = call i32 @dup2(i32 %31, i32 1)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = load i8*, i8** %6
%38 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%39 = call i32 @execle(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %37, i32* null, i8** %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
%44 = load i32, i32* %9
%45 = call i32 @waitpid(i32 %44, i32* %10, i32 0)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
br label %50
50: ; preds = %49, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"RSS_FEED=http://rss.cnn.com/rss/edition.rss\00"
@__const.main.vars = [2 x i8*] [i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [12 x i8] c"stories.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [23 x i8] c"Can't open stories.txt\00"
@.str.4 = [19 x i8] c"Can't fork process\00"
@.str.5 = [31 x i8] c"Can't redirect Standard Output\00"
@.str.6 = [16 x i8] c"/usr/bin/python\00"
@.str.7 = [15 x i8] c"./rssgossip.py\00"
@.str.8 = [17 x i8] c"Can't run script\00"
@.str.9 = [32 x i8] c"Error waiting for child process\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8*]
%4 = alloca i32
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = bitcast [2 x i8*]* %3 to i8*
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = tail call i32 (...) @fork()
switch i32 %13, label %35 [
i32 -1, label %14
i32 0, label %16
]
14: ; preds = %12
%15 = tail call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %35
16: ; preds = %12
%17 = tail call i32 @fileno(i32* %8)
%18 = tail call i32 @dup2(i32 %17, i32 1)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%24 = call i32 @execle(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %6, i32* null, i8** %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = bitcast i32* %4 to i8*
%30 = call i32 @waitpid(i32 0, i32* %4, i32 0)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
br label %35
35: ; preds = %14, %12, %34
ret i32 0
}