#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*/ exit(int);
int /*<<< orphan*/ htxcmd_display_usage(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *htxcmd_get_ecg_name(int argument_count, char *argument_vector[],
                          char *ecg_name) {
  int i;
  char temp_error_string[512];
  ecg_name[0] = '\0';
  for (i = 1; i < argument_count; i++) {
    if (((strncmp("-ecg", argument_vector[i], strlen("-ecg"))) == 0) ||
        ((strncmp("-mdt", argument_vector[i], strlen("-mdt"))) == 0)) {
      i++;
      if (i >= argument_count) {
        htxcmd_display_usage(
            "Error : ECG name is not provided with <-ecg> option");
        exit(1);
      }
      if (strlen(argument_vector[i]) > 512) {
        sprintf(temp_error_string,
                "Error : provided ECG name exceeded maximum length limit value "
                "<%d>",
                256);
        htxcmd_display_usage(temp_error_string);
        exit(1);
      }
      if (argument_vector[i][0] != '-') {
        strcpy(ecg_name, argument_vector[i]);
        break;
      } else {
        htxcmd_display_usage("Error : invalid ECG name is provided");
        exit(1);
      }
    }
  }
  if ((strlen(ecg_name) > 0) && (strchr(ecg_name, '/') == NULL)) {
    strcpy(temp_error_string, ecg_name);
    sprintf(ecg_name, "/usr/lpp/htx/mdt/%s", temp_error_string);
  }
  return ecg_name;
}


x86 assembly (clang, -O0):
<htxcmd_get_ecg_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12ee <htxcmd_get_ecg_name+0x17e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x228(%rbp)
lea    0xe46(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
lea    0xe31(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     121c <htxcmd_get_ecg_name+0xac>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x230(%rbp)
lea    0xe0d(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x230(%rbp),%rsi
mov    %eax,%edx
lea    0xdf8(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12db <htxcmd_get_ecg_name+0x16b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     1247 <htxcmd_get_ecg_name+0xd7>
lea    0xdd2(%rip),%rdi
call   1060 <htxcmd_display_usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
cmp    $0x200,%eax
jle    1293 <htxcmd_get_ecg_name+0x123>
lea    -0x220(%rbp),%rdi
lea    0xdcd(%rip),%rsi
mov    $0x100,%edx
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x220(%rbp),%rdi
call   1060 <htxcmd_display_usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     12c5 <htxcmd_get_ecg_name+0x155>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
jmp    12ee <htxcmd_get_ecg_name+0x17e>
lea    0xdb5(%rip),%rdi
call   1060 <htxcmd_display_usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12e0 <htxcmd_get_ecg_name+0x170>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1194 <htxcmd_get_ecg_name+0x24>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jle    1341 <htxcmd_get_ecg_name+0x1d1>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
jne    1341 <htxcmd_get_ecg_name+0x1d1>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    0xd6c(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htxcmd_get_ecg_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,0x8(%rsp)
movb   $0x0,(%rdx)
mov    %edi,0x4(%rsp)
cmp    $0x2,%edi
jl     1244 <htxcmd_get_ecg_name+0xd4>
mov    %rsi,%rbx
mov    0x4(%rsp),%eax
mov    $0x1,%r14d
sub    %rax,%r14
mov    $0x2,%r15d
lea    0xe4d(%rip),%r13
lea    0xe4b(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    -0x8(%rbx,%r15,8),%rbp
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1212 <htxcmd_get_ecg_name+0xa2>
mov    -0x8(%rbx,%r15,8),%rbp
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1212 <htxcmd_get_ecg_name+0xa2>
lea    (%r14,%r15,1),%rax
add    $0x1,%rax
add    $0x1,%r15
cmp    $0x2,%rax
jne    11c0 <htxcmd_get_ecg_name+0x50>
jmp    1244 <htxcmd_get_ecg_name+0xd4>
cmp    0x4(%rsp),%r15d
jge    12a0 <htxcmd_get_ecg_name+0x130>
mov    (%rbx,%r15,8),%rdi
call   1050 <strlen@plt>
cmp    $0x201,%eax
jge    12a9 <htxcmd_get_ecg_name+0x139>
mov    (%rbx,%r15,8),%rsi
cmpb   $0x2d,(%rsi)
je     12c9 <htxcmd_get_ecg_name+0x159>
mov    0x8(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    128b <htxcmd_get_ecg_name+0x11b>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
jne    128b <htxcmd_get_ecg_name+0x11b>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0xe28(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbp,%rax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd63(%rip),%rdi
jmp    12d0 <htxcmd_get_ecg_name+0x160>
lea    0xd8e(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%edx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
jmp    12d0 <htxcmd_get_ecg_name+0x160>
lea    0xdb1(%rip),%rdi
call   1060 <htxcmd_display_usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"-ecg\00"
@.str.1 = [5 x i8] c"-mdt\00"
@.str.2 = [52 x i8] c"Error : ECG name is not provided with <-ecg> option\00"
@.str.3 = [67 x i8] c"Error : provided ECG name exceeded maximum length limit value <%d>\00"
@.str.4 = [37 x i8] c"Error : invalid ECG name is provided\00"
@.str.5 = [20 x i8] c"/usr/lpp/htx/mdt/%s\00"
define i8* @htxcmd_get_ecg_name(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [512 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 0, i8* %10
store i32 1, i32* %7
br label %11
11: ; preds = %78, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %81
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%31 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %77
33: ; preds = %24, %15
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = load i32, i32* %4
%38 = icmp sge i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %33
%43 = load i8**, i8*** %5
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @strlen(i8* %47)
%49 = icmp sgt i32 %48, 512
br i1 %49, label %50, label %56
50: ; preds = %42
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 256)
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%54 = call i32 @htxcmd_display_usage(i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %42
%57 = load i8**, i8*** %5
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = getelementptr inbounds i8, i8* %61, i64 0
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp ne i32 %64, 45
br i1 %65, label %66, label %74
66: ; preds = %56
%67 = load i8*, i8** %6
%68 = load i8**, i8*** %5
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @strcpy(i8* %67, i8* %72)
br label %81
74: ; preds = %56
%75 = call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %24
br label %78
78: ; preds = %77
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %11
81: ; preds = %66, %11
%82 = load i8*, i8** %6
%83 = call i32 @strlen(i8* %82)
%84 = icmp sgt i32 %83, 0
br i1 %84, label %85, label %96
85: ; preds = %81
%86 = load i8*, i8** %6
%87 = call i32* @strchr(i8* %86, i8 signext 47)
%88 = icmp eq i32* %87, null
br i1 %88, label %89, label %96
89: ; preds = %85
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%91 = load i8*, i8** %6
%92 = call i32 @strcpy(i8* %90, i8* %91)
%93 = load i8*, i8** %6
%94 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%95 = call i32 (i8*, i8*, ...) @sprintf(i8* %93, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %94)
br label %96
96: ; preds = %89, %85, %81
%97 = load i8*, i8** %6
ret i8* %97
}

LLVM IR (-O2):
@.str = [5 x i8] c"-ecg\00"
@.str.1 = [5 x i8] c"-mdt\00"
@.str.2 = [52 x i8] c"Error : ECG name is not provided with <-ecg> option\00"
@.str.3 = [67 x i8] c"Error : provided ECG name exceeded maximum length limit value <%d>\00"
@.str.4 = [37 x i8] c"Error : invalid ECG name is provided\00"
@.str.5 = [20 x i8] c"/usr/lpp/htx/mdt/%s\00"
define i8* @htxcmd_get_ecg_name(i32 %0, i8** nocapture %1, i8* returned %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
store i8 0, i8* %2
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %50
7: ; preds = %3
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %47
%10 = phi i64 [ 1, %7 ], [ %48, %47 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %9
%17 = load i8*, i8** %11
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %47
21: ; preds = %16, %9
%22 = trunc i64 %10 to i32
%23 = add nuw nsw i32 %22, 1
%24 = icmp slt i32 %23, %0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = tail call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = zext i32 %23 to i64
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = tail call i32 @strlen(i8* %31)
%33 = icmp sgt i32 %32, 512
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 256)
%36 = call i32 @htxcmd_display_usage(i8* %5)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = load i8*, i8** %30
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 45
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = tail call i32 @strcpy(i8* %2, i8* %39)
br label %50
44: ; preds = %38
%45 = tail call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %16
%48 = add nuw nsw i64 %10, 1
%49 = icmp eq i64 %48, %8
br i1 %49, label %50, label %9
50: ; preds = %47, %3, %42
%51 = tail call i32 @strlen(i8* %2)
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = tail call i32* @strchr(i8* %2, i8 signext 47)
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 @strcpy(i8* %5, i8* %2)
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %59
59: ; preds = %56, %53, %50
ret i8* %2
}