#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ detect_tags_file();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, int /*<<< orphan*/);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
bool id_tagged(char *id) {
  char file_name[30] = "/ctf_ucon2/";
  FILE *file = NULL;
  char buffer[10];
  printf("Checking if this level was already tagged...\n");
  sleep(0);
  strcat(file_name, detect_tags_file());
  file = fopen(file_name, "r");
  if (file != NULL) {
    while (fgets(buffer, 10, file) != NULL) {
      if (strlen(buffer) != 5) {
        printf("[FAIL] Tag file corrupted! Contact the staff!\n");
        exit(EXIT_FAILURE);
      }
    }
    fseek(file, 0, SEEK_SET);
    while (fgets(buffer, 10, file) != NULL) {
      if (strncmp(id, buffer, 4) == 0) {
        return true;
      }
    }
    fclose(file);
    return false;
  } else {
    printf("[FAIL] This is not a taggable level\n\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<id_tagged>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xe3d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe37(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe35(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe2f(%rip),%ax
mov    %ax,-0x14(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xe1e(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10d0 <sleep@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1060 <detect_tags_file@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   10b0 <strcat@plt>
lea    -0x30(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1309 <id_tagged+0x159>
jmp    124a <id_tagged+0x9a>
lea    -0x42(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0xa,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1297 <id_tagged+0xe7>
lea    -0x42(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
je     1292 <id_tagged+0xe2>
lea    0xdcf(%rip),%rdi
call   1070 <printf@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    124a <id_tagged+0x9a>
mov    -0x38(%rbp),%rdi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
lea    -0x42(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0xa,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12f4 <id_tagged+0x144>
mov    -0x10(%rbp),%rdi
lea    -0x42(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ef <id_tagged+0x13f>
movl   $0x1,-0x4(%rbp)
jmp    1323 <id_tagged+0x173>
jmp    12ab <id_tagged+0xfb>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <id_tagged+0x173>
lea    0xd6d(%rip),%rdi
call   1070 <printf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id_tagged>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
movups 0xe49(%rip),%xmm0
movups %xmm0,0x1e(%rsp)
movaps 0xe2f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe43(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <sleep@plt>
xor    %eax,%eax
call   1070 <detect_tags_file@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <strcat@plt>
lea    0xe18(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12c7 <id_tagged+0x117>
mov    %rax,%r12
lea    0x6(%rsp),%rbx
nop
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     125c <id_tagged+0xac>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x5,%eax
je     1220 <id_tagged+0x70>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0x6(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0xa,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12b1 <id_tagged+0x101>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1280 <id_tagged+0xd0>
mov    $0x1,%eax
jmp    12bb <id_tagged+0x10b>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd7f(%rip),%rdi
jmp    1249 <id_tagged+0x99>

LLVM IR (-O0):
@__const.id_tagged.file_name = [30 x i8] c"/ctf_ucon2/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [46 x i8] c"Checking if this level was already tagged...\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [47 x i8] c"[FAIL] Tag file corrupted! Contact the staff!\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [38 x i8] c"[FAIL] This is not a taggable level\0A\0A\00"
define i32 @id_tagged(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [30 x i8]
%5 = alloca i32*
%6 = alloca [10 x i8]
store i8* %0, i8** %3
%7 = bitcast [30 x i8]* %4 to i8*
store i32* null, i32** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @sleep(i32 0)
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%11 = call i32 (...) @detect_tags_file()
%12 = call i32 @strcat(i8* %10, i32 %11)
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %51
17: ; preds = %1
br label %18
18: ; preds = %31, %17
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32* @fgets(i8* %19, i32 10, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = icmp ne i32 %25, 5
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
br label %18
32: ; preds = %18
%33 = load i32*, i32** %5
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
br label %36
36: ; preds = %47, %32
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%38 = load i32*, i32** %5
%39 = call i32* @fgets(i8* %37, i32 10, i32* %38)
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %48
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%44 = call i64 @strncmp(i8* %42, i8* %43, i32 4)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 1, i32* %2
br label %55
47: ; preds = %41
br label %36
48: ; preds = %36
%49 = load i32*, i32** %5
%50 = call i32 @fclose(i32* %49)
store i32 0, i32* %2
br label %55
51: ; preds = %1
%52 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %48, %46
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@__const.id_tagged.file_name = [30 x i8] c"/ctf_ucon2/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@str = [45 x i8] c"Checking if this level was already tagged...\00"
@str.4 = [37 x i8] c"[FAIL] This is not a taggable level\0A\00"
@str.5 = [46 x i8] c"[FAIL] Tag file corrupted! Contact the staff!\00"
define i32 @id_tagged(i8* %0) {
%2 = alloca [30 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @sleep(i32 0)
%8 = tail call i32 (...) @detect_tags_file()
%9 = call i32 @strcat(i8* %4, i32 %8)
%10 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %33, label %12
12: ; preds = %1, %15
%13 = call i32* @fgets(i8* %5, i32 10, i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = call i32 @strlen(i8* %5)
%17 = icmp eq i32 %16, 5
br i1 %17, label %12, label %18
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.5, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %10, i32 0, i32 %23)
br label %25
25: ; preds = %28, %22
%26 = call i32* @fgets(i8* %5, i32 10, i32* %10)
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = call i64 @strncmp(i8* %0, i8* %5, i32 4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %25
31: ; preds = %25
%32 = call i32 @fclose(i32* %10)
br label %37
33: ; preds = %1
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.4, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28, %31
%38 = phi i32 [ 0, %31 ], [ 1, %28 ]
ret i32 %38
}