#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 */
struct mutex {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ __CPROVER_assert(int, char *);
int /*<<< orphan*/ __CPROVER_atomic_begin();
int /*<<< orphan*/ __CPROVER_atomic_end();
void mutex_init(struct mutex *lock) {
  int __cil_tmp2;
  int __cil_tmp3;
  unsigned long __cil_tmp4;
  unsigned long __cil_tmp5;
  {
    {
      __CPROVER_atomic_begin();
      __cil_tmp2 = *((int *)lock);
      __cil_tmp3 = !__cil_tmp2;
      __CPROVER_assert(__cil_tmp3, "Locked mutex must not be reinitialized");
      *((int *)lock) = 0;
      __cil_tmp4 = (unsigned long)lock;
      __cil_tmp5 = __cil_tmp4 + 4;
      *((int *)__cil_tmp5) = 1;
      __CPROVER_atomic_end();
    }
    return;
  }
}


x86 assembly (clang, -O0):
<mutex_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <__CPROVER_atomic_begin@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe99(%rip),%rsi
call   1050 <__CPROVER_assert@plt>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    $0x0,%al
call   1040 <__CPROVER_atomic_end@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutex_init>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <__CPROVER_atomic_begin@plt>
xor    %edi,%edi
cmpl   $0x0,(%rbx)
sete   %dil
lea    0xeb5(%rip),%rsi
call   1050 <__CPROVER_assert@plt>
movabs $0x100000000,%rax
mov    %rax,(%rbx)
xor    %eax,%eax
pop    %rbx
jmp    1040 <__CPROVER_atomic_end@plt>

LLVM IR (-O0):
%struct.mutex = type { i32 }
@.str = [39 x i8] c"Locked mutex must not be reinitialized\00"
define void @mutex_init(%struct.mutex* %0) {
%2 = alloca %struct.mutex*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store %struct.mutex* %0, %struct.mutex** %2
%7 = call i32 (...) @__CPROVER_atomic_begin()
%8 = load %struct.mutex*, %struct.mutex** %2
%9 = bitcast %struct.mutex* %8 to i32*
%10 = load i32, i32* %9
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = call i32 @__CPROVER_assert(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%17 = load %struct.mutex*, %struct.mutex** %2
%18 = bitcast %struct.mutex* %17 to i32*
store i32 0, i32* %18
%19 = load %struct.mutex*, %struct.mutex** %2
%20 = ptrtoint %struct.mutex* %19 to i64
store i64 %20, i64* %5
%21 = load i64, i64* %5
%22 = add i64 %21, 4
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = inttoptr i64 %23 to i32*
store i32 1, i32* %24
%25 = call i32 (...) @__CPROVER_atomic_end()
ret void
}

LLVM IR (-O2):
%struct.mutex = type { i32 }
@.str = [39 x i8] c"Locked mutex must not be reinitialized\00"
define void @mutex_init(%struct.mutex* %0) {
%2 = tail call i32 (...) @__CPROVER_atomic_begin()
%3 = getelementptr %struct.mutex, %struct.mutex* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @__CPROVER_assert(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
%8 = ptrtoint %struct.mutex* %0 to i64
%9 = add i64 %8, 4
%10 = inttoptr i64 %9 to i32*
store i32 1, i32* %10
%11 = tail call i32 (...) @__CPROVER_atomic_end()
ret void
}