#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);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ENgeterror(int errcode, char *errmsg, int n) {
  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), n);
  }
  if (strlen(errmsg) == 0)
    return (251);
  else
    return (0);
}


x86 assembly (clang, -O0):
<ENgeterror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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,-0x20(%rbp)
sub    $0x5,%eax
ja     11fb <ENgeterror+0xcb>
mov    -0x20(%rbp),%rax
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe9f(%rip),%rsi
call   1030 <strncpy@plt>
jmp    121a <ENgeterror+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xeb1(%rip),%rsi
call   1030 <strncpy@plt>
jmp    121a <ENgeterror+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xec8(%rip),%rsi
call   1030 <strncpy@plt>
jmp    121a <ENgeterror+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xece(%rip),%rsi
call   1030 <strncpy@plt>
jmp    121a <ENgeterror+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xee9(%rip),%rsi
call   1030 <strncpy@plt>
jmp    121a <ENgeterror+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xefd(%rip),%rsi
call   1030 <strncpy@plt>
jmp    121a <ENgeterror+0xea>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <geterrmsg@plt>
mov    -0x28(%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    1239 <ENgeterror+0x109>
movl   $0xfb,-0x4(%rbp)
jmp    1240 <ENgeterror+0x110>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ENgeterror>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
lea    -0x1(%rdi),%eax
cmp    $0x6,%eax
jae    1142 <ENgeterror+0x22>
cltq
lea    0xfc7(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    114a <ENgeterror+0x2a>
call   1040 <geterrmsg@plt>
mov    %rax,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
xor    %ecx,%ecx
cmpb   $0x0,(%rbx)
mov    $0xfb,%eax
cmovne %ecx,%eax
add    $0x8,%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 @ENgeterror(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
switch i32 %8, label %33 [
i32 1, label %9
i32 2, label %13
i32 3, label %17
i32 4, label %21
i32 5, label %25
i32 6, label %29
]
9: ; preds = %3
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %39
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @strncpy(i8* %14, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %39
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = call i32 @strncpy(i8* %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %39
21: ; preds = %3
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %39
25: ; preds = %3
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = call i32 @strncpy(i8* %26, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %39
29: ; preds = %3
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = call i32 @strncpy(i8* %30, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %31)
br label %39
33: ; preds = %3
%34 = load i8*, i8** %6
%35 = load i32, i32* %5
%36 = call i8* @geterrmsg(i32 %35)
%37 = load i32, i32* %7
%38 = call i32 @strncpy(i8* %34, i8* %36, i32 %37)
br label %39
39: ; preds = %33, %29, %25, %21, %17, %13, %9
%40 = load i8*, i8** %6
%41 = call i64 @strlen(i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 251, i32* %4
br label %45
44: ; preds = %39
store i32 0, i32* %4
br label %45
45: ; preds = %44, %43
%46 = load i32, i32* %4
ret i32 %46
}

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"
@reltable.ENgeterror = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([42 x i8]* @.str to i64), i64 ptrtoint ([6 x i32]* @reltable.ENgeterror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([47 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.ENgeterror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.ENgeterror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([51 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.ENgeterror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([44 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.ENgeterror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([40 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.ENgeterror to i64)) to i32)]
define i32 @ENgeterror(i32 %0, i8* %1, i32 %2) {
%4 = add i32 %0, -1
%5 = icmp ult i32 %4, 6
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i8* @geterrmsg(i32 %0)
br label %12
8: ; preds = %3
%9 = sext i32 %4 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.ENgeterror to i8*), i64 %10)
br label %12
12: ; preds = %8, %6
%13 = phi i8* [ %7, %6 ], [ %11, %8 ]
%14 = tail call i32 @strncpy(i8* %1, i8* %13, i32 %2)
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 0
%17 = select i1 %16, i32 251, i32 0
ret i32 %17
}