#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*/ lock();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ unlock();
int big_func(int val) {
  lock();
  int sum = 0;
  int i;
  static int count = 0;
  printf("number of threads here is %d\n", ++count);
  for (i = 0; i < val; i++)
    sum += val;
  count--;
  unlock();
  return sum;
}


x86 assembly (clang, -O0):
<big_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <lock@plt>
movl   $0x0,-0x8(%rbp)
mov    0x2eed(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2ee4(%rip)
lea    0xea1(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118e <big_func+0x5e>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <big_func+0x3b>
mov    0x2ea8(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2e9f(%rip)
mov    $0x0,%al
call   1030 <unlock@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<big_func>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <lock@plt>
mov    0x2ef6(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2eed(%rip)
lea    0xeaa(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%ebp
imul   %ebx,%ebp
test   %ebx,%ebx
cmovle %r14d,%ebp
addl   $0xffffffff,0x2ecf(%rip)
xor    %eax,%eax
call   1030 <unlock@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@big_func.count = internal global i32 0
@.str = [30 x i8] c"number of threads here is %d\0A\00"
define i32 @big_func(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 (...) @lock()
store i32 0, i32* %3
%6 = load i32, i32* @big_func.count
%7 = add nsw i32 %6, 1
store i32 %7, i32* @big_func.count
%8 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 0, i32* %4
br label %9
9: ; preds = %17, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = add nsw i32 %15, %14
store i32 %16, i32* %3
br label %17
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %9
20: ; preds = %9
%21 = load i32, i32* @big_func.count
%22 = add nsw i32 %21, -1
store i32 %22, i32* @big_func.count
%23 = call i32 (...) @unlock()
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@big_func.count = internal unnamed_addr global i32 0
@.str = [30 x i8] c"number of threads here is %d\0A\00"
define i32 @big_func(i32 %0) {
%2 = tail call i32 (...) @lock()
%3 = load i32, i32* @big_func.count
%4 = add nsw i32 %3, 1
store i32 %4, i32* @big_func.count
%5 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %0, 0
%7 = mul i32 %0, %0
%8 = select i1 %6, i32 %7, i32 0
%9 = load i32, i32* @big_func.count
%10 = add nsw i32 %9, -1
store i32 %10, i32* @big_func.count
%11 = tail call i32 (...) @unlock()
ret i32 %8
}