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

/* Variables and functions */
scalar_t__ fileExists(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ iReplaceS(char **, char *, char *, int);
int /*<<< orphan*/ puts(char *);
char *readFileToS(char *);
int /*<<< orphan*/ writeFileS(char *, char *);
int main(int ARGC, char **ARGV) {
  if (fileExists("/etc/alpine-release")) {
    puts("alpine linux detected, add define MUSL_LIBC=1 in Makefile and "
         "build.sh");
    char *M = readFileToS("Makefile");
    char *B = readFileToS("build.sh");
    iReplaceS(&M, "-pipe", "-pipe -DMUSL_LIBC=1", 1);
    iReplaceS(&B, "-pipe", "-pipe -DMUSL_LIBC=1", 1);
    writeFileS("Makefile", M);
    writeFileS("build.sh", B);
    free(M);
    free(B);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1060 <fileExists@plt>
cmp    $0x0,%rax
je     1222 <main+0xc2>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
lea    0xebc(%rip),%rdi
call   1050 <readFileToS@plt>
mov    %rax,-0x18(%rbp)
lea    0xea3(%rip),%rdi
call   1050 <readFileToS@plt>
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xea1(%rip),%rsi
lea    0xea0(%rip),%rdx
mov    $0x1,%ecx
call   1080 <iReplaceS@plt>
lea    -0x20(%rbp),%rdi
lea    0xe85(%rip),%rsi
lea    0xe84(%rip),%rdx
mov    $0x1,%ecx
call   1080 <iReplaceS@plt>
mov    -0x18(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1070 <writeFileS@plt>
mov    -0x20(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1070 <writeFileS@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8e(%rip),%rdi
call   1060 <fileExists@plt>
test   %rax,%rax
je     121a <main+0xba>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
lea    0xec8(%rip),%r14
mov    %r14,%rdi
call   1050 <readFileToS@plt>
mov    %rax,0x10(%rsp)
lea    0xeab(%rip),%r15
mov    %r15,%rdi
call   1050 <readFileToS@plt>
mov    %rax,0x8(%rsp)
lea    0xea9(%rip),%rbx
lea    0xea8(%rip),%r12
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    $0x1,%ecx
call   1080 <iReplaceS@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    $0x1,%ecx
call   1080 <iReplaceS@plt>
mov    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1070 <writeFileS@plt>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1070 <writeFileS@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/etc/alpine-release\00"
@.str.1 = [71 x i8] c"alpine linux detected, add define MUSL_LIBC=1 in Makefile and build.sh\00"
@.str.2 = [9 x i8] c"Makefile\00"
@.str.3 = [9 x i8] c"build.sh\00"
@.str.4 = [6 x i8] c"-pipe\00"
@.str.5 = [20 x i8] c"-pipe -DMUSL_LIBC=1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @fileExists(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%12 = call i8* @readFileToS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %12, i8** %6
%13 = call i8* @readFileToS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %13, i8** %7
%14 = call i32 @iReplaceS(i8** %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 1)
%15 = call i32 @iReplaceS(i8** %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 1)
%16 = load i8*, i8** %6
%17 = call i32 @writeFileS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %7
%19 = call i32 @writeFileS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %10, %2
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [20 x i8] c"/etc/alpine-release\00"
@.str.1 = [71 x i8] c"alpine linux detected, add define MUSL_LIBC=1 in Makefile and build.sh\00"
@.str.2 = [9 x i8] c"Makefile\00"
@.str.3 = [9 x i8] c"build.sh\00"
@.str.4 = [6 x i8] c"-pipe\00"
@.str.5 = [20 x i8] c"-pipe -DMUSL_LIBC=1\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = tail call i64 @fileExists(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%9 = bitcast i8** %3 to i8*
%10 = tail call i8* @readFileToS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %10, i8** %3
%11 = bitcast i8** %4 to i8*
%12 = tail call i8* @readFileToS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %12, i8** %4
%13 = call i32 @iReplaceS(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 1)
%14 = call i32 @iReplaceS(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 1)
%15 = load i8*, i8** %3
%16 = call i32 @writeFileS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @writeFileS(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %7, %2
ret i32 0
}