#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_mutex_t;

/* Variables and functions */
int /*<<< orphan*/ pthread_mutex_lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutex_unlock(int /*<<< orphan*/ *);
int rand();
void compute(pthread_mutex_t *l) {
  int a[100];
  int i;
  for (i = 0; i < 100; i++) {
    pthread_mutex_lock(l);
    a[i] = rand();
    pthread_mutex_unlock(l);
  }
  int sum = 0;
  for (i = 0; i < 100; i++) {
    sum += a[i];
  }
  int m = sum / 100;
  m++;
  return;
}


x86 assembly (clang, -O0):
<compute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    1193 <compute+0x63>
mov    -0x8(%rbp),%rdi
call   1040 <pthread_mutex_lock@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%ecx
movslq -0x1a4(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x8(%rbp),%rdi
call   1030 <pthread_mutex_unlock@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1149 <compute+0x19>
movl   $0x0,-0x1a8(%rbp)
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    11e2 <compute+0xb2>
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
add    -0x1a8(%rbp),%eax
mov    %eax,-0x1a8(%rbp)
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    11a7 <compute+0x77>
mov    -0x1a8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <pthread_mutex_lock@plt>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %rbx,%rdi
call   1030 <pthread_mutex_unlock@plt>
add    $0xffffffff,%ebp
jne    1140 <compute+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @compute(i32* %0) {
%2 = alloca i32*
%3 = alloca [100 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
br label %7
7: ; preds = %19, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = call i32 @pthread_mutex_lock(i32* %11)
%13 = call i32 (...) @rand()
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %15
store i32 %13, i32* %16
%17 = load i32*, i32** %2
%18 = call i32 @pthread_mutex_unlock(i32* %17)
br label %19
19: ; preds = %10
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %7
22: ; preds = %7
store i32 0, i32* %5
store i32 0, i32* %4
br label %23
23: ; preds = %33, %22
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 100
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = load i32, i32* %5
%32 = add nsw i32 %31, %30
store i32 %32, i32* %5
br label %33
33: ; preds = %26
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %23
36: ; preds = %23
%37 = load i32, i32* %5
%38 = sdiv i32 %37, 100
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
ret void
}

LLVM IR (-O2):
define void @compute(i32* %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 0, %1 ], [ %7, %2 ]
%4 = tail call i32 @pthread_mutex_lock(i32* %0)
%5 = tail call i32 (...) @rand()
%6 = tail call i32 @pthread_mutex_unlock(i32* %0)
%7 = add nuw nsw i32 %3, 1
%8 = icmp eq i32 %7, 100
br i1 %8, label %9, label %2
9: ; preds = %2
ret void
}