#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*/ pthread_t;
typedef int /*<<< orphan*/ pthread_mutex_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_MUTEX_INITIALIZER;
void *f1();
int /*<<< orphan*/ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  void *(*)(), int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutex_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
main() {
  srand(time(NULL));
  pthread_t f2_thread, f1_thread;
  void *f2(), *f1();
  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  pthread_create(&f1_thread, NULL, f1, &mutex);
  pthread_create(&f2_thread, NULL, f2, &mutex);
  pthread_join(f1_thread, NULL);
  pthread_join(f2_thread, NULL);
  pthread_mutex_destroy(&mutex);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    0x2e65(%rip),%rdx
lea    -0xc(%rbp),%rcx
call   1060 <pthread_create@plt>
lea    -0x4(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    0x2e2d(%rip),%rdx
lea    -0xc(%rbp),%rcx
call   1060 <pthread_create@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <pthread_join@plt>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <pthread_join@plt>
lea    -0xc(%rbp),%rdi
call   1030 <pthread_mutex_destroy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e71(%rip),%rdx
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rbx
xor    %esi,%esi
mov    %rbx,%rcx
call   1060 <pthread_create@plt>
mov    0x2e36(%rip),%rdx
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rcx
call   1060 <pthread_create@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1070 <pthread_join@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1070 <pthread_join@plt>
mov    %rbx,%rdi
call   1030 <pthread_mutex_destroy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@PTHREAD_MUTEX_INITIALIZER = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @time(i32* null)
%5 = call i32 @srand(i32 %4)
%6 = load i32, i32* @PTHREAD_MUTEX_INITIALIZER
store i32 %6, i32* %3
%7 = call i32 @pthread_create(i32* %2, i32* null, i8* (...)* @f1, i32* %3)
%8 = call i32 @pthread_create(i32* %1, i32* null, i8* (...)* @f2, i32* %3)
%9 = load i32, i32* %2
%10 = call i32 @pthread_join(i32 %9, i32* null)
%11 = load i32, i32* %1
%12 = call i32 @pthread_join(i32 %11, i32* null)
%13 = call i32 @pthread_mutex_destroy(i32* %3)
ret i32 0
}

LLVM IR (-O2):
@PTHREAD_MUTEX_INITIALIZER = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = load i32, i32* @PTHREAD_MUTEX_INITIALIZER
store i32 %9, i32* %3
%10 = call i32 @pthread_create(i32* %2, i32* null, i8* (...)* @f1, i32* %3)
%11 = call i32 @pthread_create(i32* %1, i32* null, i8* (...)* @f2, i32* %3)
%12 = load i32, i32* %2
%13 = call i32 @pthread_join(i32 %12, i32* null)
%14 = load i32, i32* %1
%15 = call i32 @pthread_join(i32 %14, i32* null)
%16 = call i32 @pthread_mutex_destroy(i32* %3)
ret i32 0
}