#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 sharedtest_installed();
int sharedtest_not_installed();
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc > 1) {
    FILE *fp = fopen(argv[1], "wt");
    fprintf(fp, "int main(void) { return 0; }\n");
    fclose(fp);
  }
  if (sharedtest_installed() == 12345 && sharedtest_not_installed() == 12345) {
    return 0;
  } else {
    fprintf(stderr, "%s: Library functions did not return correct values\n",
            argv[0]);
    return 1;
  }
}


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)
cmpl   $0x1,-0x8(%rbp)
jle    11a5 <main+0x55>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%edi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1050 <sharedtest_installed@plt>
cmp    $0x3039,%eax
jne    11d5 <main+0x85>
mov    $0x0,%al
call   1070 <sharedtest_not_installed@plt>
cmp    $0x3039,%eax
jne    11d5 <main+0x85>
movl   $0x0,-0x4(%rbp)
jmp    11fa <main+0xaa>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     1186 <main+0x36>
mov    0x8(%rbx),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
lea    0xe8e(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <sharedtest_installed@plt>
cmp    $0x3039,%eax
jne    11a4 <main+0x54>
xor    %eax,%eax
call   1070 <sharedtest_not_installed@plt>
cmp    $0x3039,%eax
je     11c3 <main+0x73>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wt\00"
@.str.1 = [30 x i8] c"int main(void) { return 0; }\0A\00"
@stderr = global i32 0
@.str.2 = [53 x i8] c"%s: Library functions did not return correct values\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = ptrtoint i32* %14 to i32
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32*, i32** %6
%18 = call i32 @fclose(i32* %17)
br label %19
19: ; preds = %9, %2
%20 = call i32 (...) @sharedtest_installed()
%21 = icmp eq i32 %20, 12345
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 (...) @sharedtest_not_installed()
%24 = icmp eq i32 %23, 12345
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %3
br label %32
26: ; preds = %22, %19
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 1, i32* %3
br label %32
32: ; preds = %26, %25
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"wt\00"
@.str.1 = [30 x i8] c"int main(void) { return 0; }\0A\00"
@stderr = global i32 0
@.str.2 = [53 x i8] c"%s: Library functions did not return correct values\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = ptrtoint i32* %7 to i64
%9 = trunc i64 %8 to i32
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @fclose(i32* %7)
br label %12
12: ; preds = %4, %2
%13 = tail call i32 (...) @sharedtest_installed()
%14 = icmp eq i32 %13, 12345
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 (...) @sharedtest_not_installed()
%17 = icmp eq i32 %16, 12345
br i1 %17, label %22, label %18
18: ; preds = %15, %12
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %15, %18
%23 = phi i32 [ 1, %18 ], [ 0, %15 ]
ret i32 %23
}