#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 /*<<< orphan*/ setErrorCode(int, char *);
int /*<<< orphan*/ setErrorMsg(char *, char *);
int /*<<< orphan*/ setFlag(int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int tftp_error(int code, char *msg, char *answer) {
  char errormsg[64];
  int size;
  switch (code) {
  case 1:
    strcpy(errormsg, "File not found");
    break;
  case 2:
    strcpy(errormsg, "Acces violation");
    break;
  case 4:
    strcpy(errormsg, "Illegal TFTP operation");
    break;
  case 6:
    strcpy(errormsg, "File already exists");
    break;
  case 0:
    strcpy(errormsg, msg);
  }
  setFlag(5, answer);
  setErrorCode(code, answer);
  setErrorMsg(errormsg, answer);
  size = strlen(errormsg) + 4;
  return size;
}


x86 assembly (clang, -O0):
<tftp_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x70(%rbp)
sub    $0x6,%rax
ja     11e9 <tftp_error+0x99>
mov    -0x70(%rbp),%rax
lea    0xe81(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x60(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11e9 <tftp_error+0x99>
lea    -0x60(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11e9 <tftp_error+0x99>
lea    -0x60(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11e9 <tftp_error+0x99>
lea    -0x60(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11e9 <tftp_error+0x99>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rsi
mov    $0x5,%edi
call   1070 <setFlag@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <setErrorCode@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <setErrorMsg@plt>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x4,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tftp_error>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%rbx
mov    %edi,%ebp
cmp    $0x6,%edi
ja     11a2 <tftp_error+0x52>
mov    %rsi,%rax
lea    0xeb2(%rip),%rsi
mov    %ebp,%ecx
lea    0xe8d(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    %rax,%rsi
jmp    119a <tftp_error+0x4a>
lea    0xea3(%rip),%rsi
jmp    119a <tftp_error+0x4a>
lea    0xeaa(%rip),%rsi
jmp    119a <tftp_error+0x4a>
lea    0xeb8(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
mov    $0x5,%edi
mov    %rbx,%rsi
call   1070 <setFlag@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <setErrorCode@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <setErrorMsg@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
add    $0x4,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"File not found\00"
@.str.1 = [16 x i8] c"Acces violation\00"
@.str.2 = [23 x i8] c"Illegal TFTP operation\00"
@.str.3 = [20 x i8] c"File already exists\00"
define i32 @tftp_error(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [64 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
switch i32 %9, label %26 [
i32 1, label %10
i32 2, label %13
i32 4, label %16
i32 6, label %19
i32 0, label %22
]
10: ; preds = %3
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %26
13: ; preds = %3
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %26
16: ; preds = %3
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %26
19: ; preds = %3
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %26
22: ; preds = %3
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%24 = load i8*, i8** %5
%25 = call i32 @strcpy(i8* %23, i8* %24)
br label %26
26: ; preds = %22, %3, %19, %16, %13, %10
%27 = load i8*, i8** %6
%28 = call i32 @setFlag(i32 5, i8* %27)
%29 = load i32, i32* %4
%30 = load i8*, i8** %6
%31 = call i32 @setErrorCode(i32 %29, i8* %30)
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%33 = load i8*, i8** %6
%34 = call i32 @setErrorMsg(i8* %32, i8* %33)
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = add nsw i32 %36, 4
store i32 %37, i32* %8
%38 = load i32, i32* %8
ret i32 %38
}

LLVM IR (-O2):
@.str = [15 x i8] c"File not found\00"
@.str.1 = [16 x i8] c"Acces violation\00"
@.str.2 = [23 x i8] c"Illegal TFTP operation\00"
@.str.3 = [20 x i8] c"File already exists\00"
define i32 @tftp_error(i32 %0, i8* %1, i8* %2) {
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
switch i32 %0, label %13 [
i32 1, label %10
i32 2, label %6
i32 4, label %7
i32 6, label %8
i32 0, label %9
]
6: ; preds = %3
br label %10
7: ; preds = %3
br label %10
8: ; preds = %3
br label %10
9: ; preds = %3
br label %10
10: ; preds = %3, %6, %7, %8, %9
%11 = phi i8* [ %1, %9 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %3 ]
%12 = call i32 @strcpy(i8* %5, i8* %11)
br label %13
13: ; preds = %10, %3
%14 = call i32 @setFlag(i32 5, i8* %2)
%15 = call i32 @setErrorCode(i32 %0, i8* %2)
%16 = call i32 @setErrorMsg(i8* %5, i8* %2)
%17 = call i32 @strlen(i8* %5)
%18 = add nsw i32 %17, 4
ret i32 %18
}