#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 */
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ reading_phase(int, char const **);
int /*<<< orphan*/ writing_phase(int, char const **);
int main(int argc, char const *argv[]) {
  if (argc == 1) {
    puts("Run like this: ./threads <1st filename> ... <nth filename>");
    return 1;
  }
  puts("Executing writing phase:");
  writing_phase(argc - 1, argv);
  puts("Executing reading phase:");
  reading_phase(argc - 1, argv);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1168 <main+0x38>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <main+0x75>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1050 <writing_phase@plt>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1040 <reading_phase@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    114b <main+0x1b>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1181 <main+0x51>
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <writing_phase@plt>
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <reading_phase@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Run like this: ./threads <1st filename> ... <nth filename>\00"
@.str.1 = [25 x i8] c"Executing writing phase:\00"
@.str.2 = [25 x i8] c"Executing reading phase:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @puts(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %21
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = load i8**, i8*** %5
%15 = call i32 @writing_phase(i32 %13, i8** %14)
%16 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = load i8**, i8*** %5
%20 = call i32 @reading_phase(i32 %18, i8** %19)
store i32 0, i32* %3
br label %21
21: ; preds = %10, %8
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [59 x i8] c"Run like this: ./threads <1st filename> ... <nth filename>\00"
@.str.1 = [25 x i8] c"Executing writing phase:\00"
@.str.2 = [25 x i8] c"Executing reading phase:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %12
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%8 = add nsw i32 %0, -1
%9 = tail call i32 @writing_phase(i32 %8, i8** %1)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @reading_phase(i32 %8, i8** %1)
br label %12
12: ; preds = %6, %4
%13 = phi i32 [ 1, %4 ], [ 0, %6 ]
ret i32 %13
}