#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 msg(char *, ...);
int /*<<< orphan*/ remove(char *);
int ttlocked(char *, int);
int ttunlock(char *fname) {
  int err = 0;
  if (fname && *fname == '#')
    fname++;
  switch (ttlocked(fname, 1)) {
  case 0:
    break;
  case 1:
    err = msg("E1won't remove lock %s (not ours)", fname);
    break;
  case 2:
    err = 2;
    break;
  case 3:
    if (remove(fname)) {
      err = msg("ES2can't remove lock %s:", fname);
    } else {
      err = msg("X0removed lock file %s", fname);
    }
    break;
  default:
    err = msg("E2can't happen (ttunlock)");
    break;
  }
  return err;
}


x86 assembly (clang, -O0):
<ttunlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116a <ttunlock+0x3a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    116a <ttunlock+0x3a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <ttlocked@plt>
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     120c <ttunlock+0xdc>
mov    -0x18(%rbp),%rax
lea    0xe6e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    121d <ttunlock+0xed>
mov    -0x8(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <msg@plt>
mov    %eax,-0xc(%rbp)
jmp    121d <ttunlock+0xed>
movl   $0x2,-0xc(%rbp)
jmp    121d <ttunlock+0xed>
mov    -0x8(%rbp),%rdi
call   1030 <remove@plt>
cmp    $0x0,%eax
je     11f2 <ttunlock+0xc2>
mov    -0x8(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <msg@plt>
mov    %eax,-0xc(%rbp)
jmp    1207 <ttunlock+0xd7>
mov    -0x8(%rbp),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <msg@plt>
mov    %eax,-0xc(%rbp)
jmp    121d <ttunlock+0xed>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <msg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ttunlock>:
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     1141 <ttunlock+0x11>
cmpb   $0x23,(%rdi)
sete   %bl
add    %rdi,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <ttlocked@plt>
cmp    $0x3,%eax
ja     116e <ttunlock+0x3e>
mov    %eax,%ecx
lea    0xea4(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
lea    0xea4(%rip),%rdi
jmp    11a0 <ttunlock+0x70>
lea    0xeed(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1050 <msg@plt>
mov    $0x2,%eax
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <remove@plt>
test   %eax,%eax
je     1199 <ttunlock+0x69>
lea    0xe9b(%rip),%rdi
jmp    11a0 <ttunlock+0x70>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1050 <msg@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"E1won't remove lock %s (not ours)\00"
@.str.1 = [25 x i8] c"ES2can't remove lock %s:\00"
@.str.2 = [23 x i8] c"X0removed lock file %s\00"
@.str.3 = [26 x i8] c"E2can't happen (ttunlock)\00"
define i32 @ttunlock(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 35
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %2
br label %14
14: ; preds = %11, %6, %1
%15 = load i8*, i8** %2
%16 = call i32 @ttlocked(i8* %15, i32 1)
switch i32 %16, label %33 [
i32 0, label %17
i32 1, label %18
i32 2, label %21
i32 3, label %22
]
17: ; preds = %14
br label %35
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 %20, i32* %3
br label %35
21: ; preds = %14
store i32 2, i32* %3
br label %35
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = call i32 @remove(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %2
%28 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i32 %28, i32* %3
br label %32
29: ; preds = %22
%30 = load i8*, i8** %2
%31 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 %31, i32* %3
br label %32
32: ; preds = %29, %26
br label %35
33: ; preds = %14
%34 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 %34, i32* %3
br label %35
35: ; preds = %33, %32, %21, %18, %17
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [34 x i8] c"E1won't remove lock %s (not ours)\00"
@.str.1 = [25 x i8] c"ES2can't remove lock %s:\00"
@.str.2 = [23 x i8] c"X0removed lock file %s\00"
@.str.3 = [26 x i8] c"E2can't happen (ttunlock)\00"
define i32 @ttunlock(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %8, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 35
%6 = zext i1 %5 to i64
%7 = getelementptr i8, i8* %0, i64 %6
br label %8
8: ; preds = %3, %1
%9 = phi i8* [ null, %1 ], [ %7, %3 ]
%10 = tail call i32 @ttlocked(i8* %9, i32 1)
switch i32 %10, label %21 [
i32 0, label %23
i32 1, label %11
i32 2, label %13
i32 3, label %14
]
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %23
13: ; preds = %8
br label %23
14: ; preds = %8
%15 = tail call i32 @remove(i8* %9)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %23
19: ; preds = %14
%20 = tail call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %23
21: ; preds = %8
%22 = tail call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %17, %19, %21, %13, %11, %8
%24 = phi i32 [ %22, %21 ], [ %18, %17 ], [ %20, %19 ], [ 2, %13 ], [ %12, %11 ], [ %10, %8 ]
ret i32 %24
}