#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
void __create_tag(char *id) {
  FILE *fd;
  char *tag_name = (char *)malloc(24 * sizeof(char));
  memset(tag_name, '\0', 24);
  snprintf(tag_name, 24, "./%s.tag", id);
  fd = fopen(tag_name, "w");
  if (fd != NULL) {
    fprintf(fd, "Bang!!\n");
    fclose(fd);
  } else {
    printf("[!] Error on open a challenge tag file.\n");
  }
}


x86 assembly (clang, -O0):
<__create_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x18,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x18,%esi
lea    0xe52(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f0 <__create_tag+0x80>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11fc <__create_tag+0x8c>
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__create_tag>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
lea    0xe66(%rip),%rdx
mov    %rbx,%rdi
mov    $0x18,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e9 <__create_tag+0x79>
mov    %rax,%rbx
lea    0xe43(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>
lea    0xe23(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"./%s.tag\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"Bang!!\0A\00"
@.str.3 = [41 x i8] c"[!] Error on open a challenge tag file.\0A\00"
define void @__create_tag(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i64 @malloc(i32 24)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 24)
%9 = load i8*, i8** %4
%10 = load i8*, i8** %2
%11 = call i32 @snprintf(i8* %9, i32 24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = load i32*, i32** %3
%18 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
br label %23
21: ; preds = %1
%22 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"./%s.tag\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"Bang!!\0A\00"
@str = [40 x i8] c"[!] Error on open a challenge tag file.\00"
define void @__create_tag(i8* %0) {
%2 = tail call i64 @malloc(i32 24)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @memset(i8* %3, i8 signext 0, i32 24)
%5 = tail call i32 @snprintf(i8* %3, i32 24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 7, i64 1, i32* %6)
%10 = tail call i32 @fclose(i32* %6)
br label %13
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret void
}