#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 */
scalar_t__ check_collision(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stdout;
int main() {
  if (check_collision("testprog", 0) == 0) {
    printf("lock acquired\n");
    fflush(stdout);
  } else {
    printf("cannot acquire lock\n");
    fflush(stdout);
    return 1;
  }
  char buf;
  read(0, &buf, 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %esi,%esi
call   1040 <check_collision@plt>
cmp    $0x0,%rax
jne    1186 <main+0x46>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    11ac <main+0x6c>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c3 <main+0x83>
xor    %edi,%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1040 <check_collision@plt>
test   %rax,%rax
je     117b <main+0x3b>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x1,%ebx
jmp    11a6 <main+0x66>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"testprog\00"
@.str.1 = [15 x i8] c"lock acquired\0A\00"
@stdout = global i32 0
@.str.2 = [21 x i8] c"cannot acquire lock\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
%3 = call i64 @check_collision(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
br label %13
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = call i32 @fflush(i32 %11)
store i32 1, i32* %1
br label %15
13: ; preds = %5
%14 = call i32 @read(i32 0, i8* %2, i32 1)
store i32 0, i32* %1
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [9 x i8] c"testprog\00"
@stdout = global i32 0
@str = [20 x i8] c"cannot acquire lock\00"
@str.3 = [14 x i8] c"lock acquired\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i64 @check_collision(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%8 = call i32 @read(i32 0, i8* %1, i32 1)
br label %13
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i32 @fflush(i32 %11)
br label %13
13: ; preds = %4, %9
%14 = phi i32 [ 0, %4 ], [ 1, %9 ]
ret i32 %14
}