#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 set_terminalname(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ systemlog(int, char *);
int fget_terminalname(char buff[]) {
  int found_valid = 0;
  int i = 0;
  int v = 0;
  char tmpterminalname[256];
  ;
  systemlog(4, "fget_terminalname");
  tmpterminalname[0] = '\0';
  while (buff[i] == ' ' || buff[i] == '\t')
    i++;
  if (!strncmp(buff + i, "terminal.name: ", 15)) {
    i += 15;
    while (buff[i] == ' ' || buff[i] == '\t')
      i++;
    while (buff[i + v] != '\n') {
      tmpterminalname[v] = buff[i + v];
      v++;
    }
    tmpterminalname[v] = '\0';
    if (tmpterminalname[0] != '\0') {
      if ((found_valid = set_terminalname(tmpterminalname)) == 0) {
        systemlog(1, "ERROR: fget_terminalname: set_terminalname: an "
                     "unrecognized problem detected!");
        found_valid = -1;
      }
    } else {
      systemlog(1, "WARNING: fget_terminalname: terminalname was blank!");
      found_valid = -1;
    }
  }
  if (found_valid > 0)
    systemlog(92, "\t[DONE]");
  else
    systemlog(94, "\t[FAILD]");
  return found_valid;
}


x86 assembly (clang, -O0):
<fget_terminalname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x4,%edi
lea    0xea0(%rip),%rsi
call   1030 <systemlog@plt>
movb   $0x0,-0x120(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x121(%rbp)
je     11a1 <fget_terminalname+0x71>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x121(%rbp)
mov    -0x121(%rbp),%al
test   $0x1,%al
jne    11b4 <fget_terminalname+0x84>
jmp    11c2 <fget_terminalname+0x92>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116c <fget_terminalname+0x3c>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xe3e(%rip),%rsi
mov    $0xf,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12fc <fget_terminalname+0x1cc>
mov    -0x10(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x122(%rbp)
je     1225 <fget_terminalname+0xf5>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x122(%rbp)
mov    -0x122(%rbp),%al
test   $0x1,%al
jne    1238 <fget_terminalname+0x108>
jmp    1246 <fget_terminalname+0x116>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f0 <fget_terminalname+0xc0>
jmp    124b <fget_terminalname+0x11b>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     128e <fget_terminalname+0x15e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124b <fget_terminalname+0x11b>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
movsbl -0x120(%rbp),%eax
cmp    $0x0,%eax
je     12df <fget_terminalname+0x1af>
lea    -0x120(%rbp),%rdi
call   1050 <set_terminalname@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    12da <fget_terminalname+0x1aa>
mov    $0x1,%edi
lea    0xd54(%rip),%rsi
call   1030 <systemlog@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    12f7 <fget_terminalname+0x1c7>
mov    $0x1,%edi
lea    0xd85(%rip),%rsi
call   1030 <systemlog@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    12fc <fget_terminalname+0x1cc>
cmpl   $0x0,-0xc(%rbp)
jle    131c <fget_terminalname+0x1ec>
mov    $0x5c,%edi
lea    0xd92(%rip),%rsi
call   1030 <systemlog@plt>
jmp    132d <fget_terminalname+0x1fd>
mov    $0x5e,%edi
lea    0xd84(%rip),%rsi
call   1030 <systemlog@plt>
mov    -0xc(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fget_terminalname>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
lea    0xebb(%rip),%rsi
mov    $0x4,%edi
call   1030 <systemlog@plt>
movb   $0x0,(%rsp)
xor    %ebp,%ebp
jmp    1164 <fget_terminalname+0x34>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
movzbl (%rbx,%rbp,1),%eax
cmp    $0x20,%al
je     1160 <fget_terminalname+0x30>
cmp    $0x9,%al
je     1160 <fget_terminalname+0x30>
mov    %ebp,%edi
add    %rbx,%rdi
lea    0xe96(%rip),%rsi
mov    $0xf,%edx
call   1040 <strncmp@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    122a <fget_terminalname+0xfa>
add    $0xf,%ebp
jmp    11a4 <fget_terminalname+0x74>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
movzbl (%rbx,%rbp,1),%eax
cmp    $0x9,%al
je     11a0 <fget_terminalname+0x70>
cmp    $0x20,%al
je     11a0 <fget_terminalname+0x70>
mov    %ebp,%eax
mov    (%rbx,%rax,1),%al
cmp    $0xa,%al
jne    11bd <fget_terminalname+0x8d>
xor    %eax,%eax
jmp    11e1 <fget_terminalname+0xb1>
mov    %ebp,%ecx
lea    (%rbx,%rcx,1),%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    %al,(%rsp,%rcx,1)
movzbl (%rdx,%rcx,1),%eax
add    $0x1,%rcx
cmp    $0xa,%al
jne    11d0 <fget_terminalname+0xa0>
mov    %ecx,%eax
movb   $0x0,(%rsp,%rax,1)
cmpb   $0x0,(%rsp)
je     120a <fget_terminalname+0xda>
mov    %rsp,%rdi
call   1050 <set_terminalname@plt>
test   %eax,%eax
je     1213 <fget_terminalname+0xe3>
mov    %eax,%r14d
jle    122a <fget_terminalname+0xfa>
lea    0xea1(%rip),%rsi
mov    $0x5c,%edi
jmp    1236 <fget_terminalname+0x106>
lea    0xe5f(%rip),%rsi
jmp    121a <fget_terminalname+0xea>
lea    0xe08(%rip),%rsi
mov    $0x1,%edi
call   1030 <systemlog@plt>
mov    $0xffffffff,%r14d
lea    0xe7b(%rip),%rsi
mov    $0x5e,%edi
call   1030 <systemlog@plt>
mov    %r14d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"fget_terminalname\00"
@.str.1 = [16 x i8] c"terminal.name: \00"
@.str.2 = [78 x i8] c"ERROR: fget_terminalname: set_terminalname: an unrecognized problem detected!\00"
@.str.3 = [52 x i8] c"WARNING: fget_terminalname: terminalname was blank!\00"
@.str.4 = [8 x i8] c"\09[DONE]\00"
@.str.5 = [9 x i8] c"\09[FAILD]\00"
define i32 @fget_terminalname(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = call i32 @systemlog(i32 4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8 0, i8* %8
br label %9
9: ; preds = %27, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 32
br i1 %16, label %25, label %17
17: ; preds = %9
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 9
br label %25
25: ; preds = %17, %9
%26 = phi i1 [ true, %9 ], [ %24, %17 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %9
30: ; preds = %25
%31 = load i8*, i8** %2
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @strncmp(i8* %34, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 15)
%36 = icmp ne i32 %35, 0
br i1 %36, label %103, label %37
37: ; preds = %30
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 15
store i32 %39, i32* %4
br label %40
40: ; preds = %58, %37
%41 = load i8*, i8** %2
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 32
br i1 %47, label %56, label %48
48: ; preds = %40
%49 = load i8*, i8** %2
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 9
br label %56
56: ; preds = %48, %40
%57 = phi i1 [ true, %40 ], [ %55, %48 ]
br i1 %57, label %58, label %61
58: ; preds = %56
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %40
61: ; preds = %56
br label %62
62: ; preds = %72, %61
%63 = load i8*, i8** %2
%64 = load i32, i32* %4
%65 = load i32, i32* %5
%66 = add nsw i32 %64, %65
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %63, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 10
br i1 %71, label %72, label %85
72: ; preds = %62
%73 = load i8*, i8** %2
%74 = load i32, i32* %4
%75 = load i32, i32* %5
%76 = add nsw i32 %74, %75
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %73, i64 %77
%79 = load i8, i8* %78
%80 = load i32, i32* %5
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %81
store i8 %79, i8* %82
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
br label %62
85: ; preds = %62
%86 = load i32, i32* %5
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %87
store i8 0, i8* %88
%89 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %100
93: ; preds = %85
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%95 = call i32 @set_terminalname(i8* %94)
store i32 %95, i32* %3
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = call i32 @systemlog(i32 1, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %99
99: ; preds = %97, %93
br label %102
100: ; preds = %85
%101 = call i32 @systemlog(i32 1, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %102
102: ; preds = %100, %99
br label %103
103: ; preds = %102, %30
%104 = load i32, i32* %3
%105 = icmp sgt i32 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %103
%107 = call i32 @systemlog(i32 92, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %110
108: ; preds = %103
%109 = call i32 @systemlog(i32 94, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %110
110: ; preds = %108, %106
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
@.str = [18 x i8] c"fget_terminalname\00"
@.str.1 = [16 x i8] c"terminal.name: \00"
@.str.2 = [78 x i8] c"ERROR: fget_terminalname: set_terminalname: an unrecognized problem detected!\00"
@.str.3 = [52 x i8] c"WARNING: fget_terminalname: terminalname was blank!\00"
@.str.4 = [8 x i8] c"\09[DONE]\00"
@.str.5 = [9 x i8] c"\09[FAILD]\00"
define i32 @fget_terminalname(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @systemlog(i32 4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %3
br label %5
5: ; preds = %9, %1
%6 = phi i64 [ %10, %9 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %11 [
i8 32, label %9
i8 9, label %9
]
9: ; preds = %5, %5
%10 = add nuw i64 %6, 1
br label %5
11: ; preds = %5
%12 = and i64 %6, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 15)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %57
16: ; preds = %11
%17 = add i64 %6, 15
%18 = and i64 %17, 4294967295
br label %19
19: ; preds = %28, %16
%20 = phi i64 [ %29, %28 ], [ %18, %16 ]
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
switch i8 %22, label %23 [
i8 32, label %28
i8 9, label %28
]
23: ; preds = %19
%24 = and i64 %20, 4294967295
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %41, label %30
28: ; preds = %19, %19
%29 = add nuw i64 %20, 1
br label %19
30: ; preds = %23, %30
%31 = phi i64 [ %34, %30 ], [ 0, %23 ]
%32 = phi i8 [ %37, %30 ], [ %26, %23 ]
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %31
store i8 %32, i8* %33
%34 = add nuw i64 %31, 1
%35 = add nuw nsw i64 %34, %24
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 10
br i1 %38, label %39, label %30
39: ; preds = %30
%40 = and i64 %34, 4294967295
br label %41
41: ; preds = %39, %23
%42 = phi i64 [ 0, %23 ], [ %40, %39 ]
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %42
store i8 0, i8* %43
%44 = load i8, i8* %3
%45 = icmp eq i8 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %41
%47 = call i32 @set_terminalname(i8* %3)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = call i32 @systemlog(i32 1, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
br label %57
51: ; preds = %41
%52 = tail call i32 @systemlog(i32 1, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
br label %57
53: ; preds = %46
%54 = icmp sgt i32 %47, 0
br i1 %54, label %55, label %57
55: ; preds = %53
%56 = call i32 @systemlog(i32 92, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %60
57: ; preds = %51, %49, %11, %53
%58 = phi i32 [ %47, %53 ], [ -1, %51 ], [ -1, %49 ], [ 0, %11 ]
%59 = call i32 @systemlog(i32 94, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %57, %55
%61 = phi i32 [ %58, %57 ], [ %47, %55 ]
ret i32 %61
}