#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 fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void decrypter(char *key, FILE *ciphertext) {
  FILE *plaintext;
  char *plaintext_name = "files/059---.txt";
  int a, b, c;
  int check = 0;
  strncat(plaintext_name + 9, key, 3);
  plaintext = fopen(plaintext_name, "w");
  if (plaintext == (FILE *)NULL) {
    perror("059 decrypter: Unable to write to output");
    return;
  }
  do {
    check = fscanf(ciphertext, "%d,%d,%d", &a, &b, &c);
  } while (check == 3);
  fclose(plaintext);
  return;
}


x86 assembly (clang, -O0):
<decrypter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x9,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3,%edx
call   1050 <strncat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b8 <decrypter+0x68>
lea    0xe65(%rip),%rdi
call   1070 <perror@plt>
jmp    11ef <decrypter+0x9f>
jmp    11bd <decrypter+0x6d>
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1040 <fscanf@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
je     11bd <decrypter+0x6d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xe9e(%rip),%rdi
mov    $0x3,%edx
call   1050 <strncat@plt>
lea    0xe84(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e0 <decrypter+0x90>
mov    %rax,%r14
lea    0xea5(%rip),%r15
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1040 <fscanf@plt>
cmp    $0x3,%eax
je     11b0 <decrypter+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2c(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"files/059---.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [41 x i8] c"059 decrypter: Unable to write to output\00"
@.str.3 = [9 x i8] c"%d,%d,%d\00"
define void @decrypter(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %10
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 9
%13 = load i8*, i8** %3
%14 = call i32 @strncat(i8* %12, i8* %13, i32 3)
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %5
%17 = load i32*, i32** %5
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %31
21: ; preds = %2
br label %22
22: ; preds = %25, %21
%23 = load i32*, i32** %4
%24 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
store i32 %24, i32* %10
br label %25
25: ; preds = %22
%26 = load i32, i32* %10
%27 = icmp eq i32 %26, 3
br i1 %27, label %22, label %28
28: ; preds = %25
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %19
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"files/059---.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [41 x i8] c"059 decrypter: Unable to write to output\00"
@.str.3 = [9 x i8] c"%d,%d,%d\00"
define void @decrypter(i8* %0, i32* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @strncat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 9), i8* %0, i32 3)
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), 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 %12, label %14
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %19
14: ; preds = %2, %14
%15 = call i32 @fscanf(i32* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%16 = icmp eq i32 %15, 3
br i1 %16, label %14, label %17
17: ; preds = %14
%18 = call i32 @fclose(i32* %10)
br label %19
19: ; preds = %17, %12
ret void
}