#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 */
char *geterrmsg(int, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int EN3geterror(int errcode, char *errmsg, int n) {
  char Msg[80];
  switch (errcode) {
  case 1:
    strncpy(errmsg, "WARNING: System hydraulically unbalanced.", n);
    break;
  case 2:
    strncpy(errmsg, "WARNING: System may be hydraulically unstable.", n);
    break;
  case 3:
    strncpy(errmsg, "WARNING: System disconnected.", n);
    break;
  case 4:
    strncpy(errmsg, "WARNING: Pumps cannot deliver enough flow or head.", n);
    break;
  case 5:
    strncpy(errmsg, "WARNING: Valves cannot deliver enough flow.", n);
    break;
  case 6:
    strncpy(errmsg, "WARNING: System has negative pressures.", n);
    break;
  default:
    strncpy(errmsg, geterrmsg(errcode, Msg), n);
  }
  if (strlen(errmsg) == 0)
    return (251);
  else
    return (0);
}


x86 assembly (clang, -O0):
<EN3geterror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x78(%rbp)
sub    $0x5,%eax
ja     11fe <EN3geterror+0xce>
mov    -0x78(%rbp),%rax
lea    0xe9b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe9c(%rip),%rsi
call   1030 <strncpy@plt>
jmp    1221 <EN3geterror+0xf1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xeae(%rip),%rsi
call   1030 <strncpy@plt>
jmp    1221 <EN3geterror+0xf1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xec5(%rip),%rsi
call   1030 <strncpy@plt>
jmp    1221 <EN3geterror+0xf1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xecb(%rip),%rsi
call   1030 <strncpy@plt>
jmp    1221 <EN3geterror+0xf1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xee6(%rip),%rsi
call   1030 <strncpy@plt>
jmp    1221 <EN3geterror+0xf1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xefa(%rip),%rsi
call   1030 <strncpy@plt>
jmp    1221 <EN3geterror+0xf1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1040 <geterrmsg@plt>
mov    -0x80(%rbp),%rdi
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    1240 <EN3geterror+0x110>
movl   $0xfb,-0x4(%rbp)
jmp    1247 <EN3geterror+0x117>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EN3geterror>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
lea    -0x1(%rdi),%eax
cmp    $0x5,%eax
ja     114c <EN3geterror+0x2c>
lea    0xec6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xece(%rip),%rsi
jmp    1187 <EN3geterror+0x67>
mov    %rsp,%rsi
call   1040 <geterrmsg@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
jmp    118a <EN3geterror+0x6a>
lea    0xedf(%rip),%rsi
jmp    1187 <EN3geterror+0x67>
lea    0xf05(%rip),%rsi
jmp    1187 <EN3geterror+0x67>
lea    0xf1a(%rip),%rsi
jmp    1187 <EN3geterror+0x67>
lea    0xf44(%rip),%rsi
jmp    1187 <EN3geterror+0x67>
lea    0xf67(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
xor    %ecx,%ecx
cmpb   $0x0,(%rbx)
mov    $0xfb,%eax
cmovne %ecx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"WARNING: System hydraulically unbalanced.\00"
@.str.1 = [47 x i8] c"WARNING: System may be hydraulically unstable.\00"
@.str.2 = [30 x i8] c"WARNING: System disconnected.\00"
@.str.3 = [51 x i8] c"WARNING: Pumps cannot deliver enough flow or head.\00"
@.str.4 = [44 x i8] c"WARNING: Valves cannot deliver enough flow.\00"
@.str.5 = [40 x i8] c"WARNING: System has negative pressures.\00"
define i32 @EN3geterror(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [80 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
switch i32 %9, label %34 [
i32 1, label %10
i32 2, label %14
i32 3, label %18
i32 4, label %22
i32 5, label %26
i32 6, label %30
]
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @strncpy(i8* %11, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %41
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %41
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = call i32 @strncpy(i8* %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %41
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @strncpy(i8* %23, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %41
26: ; preds = %3
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = call i32 @strncpy(i8* %27, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %41
30: ; preds = %3
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = call i32 @strncpy(i8* %31, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %41
34: ; preds = %3
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%38 = call i8* @geterrmsg(i32 %36, i8* %37)
%39 = load i32, i32* %7
%40 = call i32 @strncpy(i8* %35, i8* %38, i32 %39)
br label %41
41: ; preds = %34, %30, %26, %22, %18, %14, %10
%42 = load i8*, i8** %6
%43 = call i64 @strlen(i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 251, i32* %4
br label %47
46: ; preds = %41
store i32 0, i32* %4
br label %47
47: ; preds = %46, %45
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str = [42 x i8] c"WARNING: System hydraulically unbalanced.\00"
@.str.1 = [47 x i8] c"WARNING: System may be hydraulically unstable.\00"
@.str.2 = [30 x i8] c"WARNING: System disconnected.\00"
@.str.3 = [51 x i8] c"WARNING: Pumps cannot deliver enough flow or head.\00"
@.str.4 = [44 x i8] c"WARNING: Valves cannot deliver enough flow.\00"
@.str.5 = [40 x i8] c"WARNING: System has negative pressures.\00"
define i32 @EN3geterror(i32 %0, i8* %1, i32 %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
switch i32 %0, label %18 [
i32 1, label %6
i32 2, label %8
i32 3, label %10
i32 4, label %12
i32 5, label %14
i32 6, label %16
]
6: ; preds = %3
%7 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %21
8: ; preds = %3
%9 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %2)
br label %21
10: ; preds = %3
%11 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %2)
br label %21
12: ; preds = %3
%13 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %2)
br label %21
14: ; preds = %3
%15 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %2)
br label %21
16: ; preds = %3
%17 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %2)
br label %21
18: ; preds = %3
%19 = call i8* @geterrmsg(i32 %0, i8* %5)
%20 = call i32 @strncpy(i8* %1, i8* %19, i32 %2)
br label %21
21: ; preds = %18, %16, %14, %12, %10, %8, %6
%22 = load i8, i8* %1
%23 = icmp eq i8 %22, 0
%24 = select i1 %23, i32 251, i32 0
ret i32 %24
}