#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  FILE *fp;
  char text[20];
  printf("Please type something to continue... \n");
  scanf("%s", text);
  fp = fopen("/opt/container/process2/data/process1_direct.txt", "w");
  if (fp == 0) {
    printf("Error! \n");
    return 1;
  }
  fprintf(fp, "This file was created by process 1");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xeb1(%rip),%rdi
call   1060 <scanf@plt>
lea    0xea8(%rip),%rdi
lea    0xed2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b5 <main+0x65>
lea    0xeb9(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <main+0x85>
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe98(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
lea    0xe8c(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b0 <main+0x60>
mov    %rax,%rbx
lea    0xea4(%rip),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11c1 <main+0x71>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Please type something to continue... \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [49 x i8] c"/opt/container/process2/data/process1_direct.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [9 x i8] c"Error! \0A\00"
@.str.5 = [35 x i8] c"This file was created by process 1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [20 x i8]
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = call i32* @fopen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %17
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
store i32 0, i32* %1
br label %17
17: ; preds = %12, %10
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [49 x i8] c"/opt/container/process2/data/process1_direct.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.5 = [35 x i8] c"This file was created by process 1\00"
@str = [38 x i8] c"Please type something to continue... \00"
@str.6 = [8 x i8] c"Error! \00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32* @fopen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
br label %12
9: ; preds = %0
%10 = call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i64 34, i64 1, i32* %5)
%11 = call i32 @fclose(i32* %5)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %13
}