#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 */
typedef int /*<<< orphan*/ str2;
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ G_LayoutSave(char *);
int /*<<< orphan*/ G_Printf(char *, ...);
scalar_t__ isalnum(char);
int trap_Argc();
int /*<<< orphan*/ trap_Argv(int, char *, int);
void Svcmd_LayoutSave_f(void) {
  char str[64];
  char str2[64 - 4];
  char *s;
  int i = 0;
  if (trap_Argc() != 2) {
    G_Printf("usage: layoutsave <name>\n");
    return;
  }
  trap_Argv(1, str, sizeof(str));
  s = &str[0];
  while (*s && i < sizeof(str2) - 1) {
    if (isalnum(*s) || *s == '-' || *s == '_') {
      str2[i++] = *s;
      str2[i] = '\0';
    }
    s++;
  }
  if (!str2[0]) {
    G_Printf("layoutsave: invalid name \"%s\"\n", str);
    return;
  }
  G_LayoutSave(str2);
}


x86 assembly (clang, -O0):
<Svcmd_LayoutSave_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x8c(%rbp)
mov    $0x0,%al
call   1050 <trap_Argc@plt>
cmp    $0x2,%eax
je     1188 <Svcmd_LayoutSave_f+0x38>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1060 <G_Printf@plt>
jmp    1294 <Svcmd_LayoutSave_f+0x144>
lea    -0x40(%rbp),%rsi
mov    $0x1,%edi
mov    $0x40,%edx
call   1070 <trap_Argv@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x8d(%rbp)
je     11d5 <Svcmd_LayoutSave_f+0x85>
movslq -0x8c(%rbp),%rax
cmp    $0x3b,%rax
setb   %al
mov    %al,-0x8d(%rbp)
mov    -0x8d(%rbp),%al
test   $0x1,%al
jne    11e8 <Svcmd_LayoutSave_f+0x98>
jmp    126a <Svcmd_LayoutSave_f+0x11a>
mov    -0x88(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
jne    1227 <Svcmd_LayoutSave_f+0xd7>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1227 <Svcmd_LayoutSave_f+0xd7>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
jne    1253 <Svcmd_LayoutSave_f+0x103>
mov    -0x88(%rbp),%rax
mov    (%rax),%cl
mov    -0x8c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8c(%rbp)
cltq
mov    %cl,-0x80(%rbp,%rax,1)
movslq -0x8c(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    11a6 <Svcmd_LayoutSave_f+0x56>
cmpb   $0x0,-0x80(%rbp)
jne    128b <Svcmd_LayoutSave_f+0x13b>
lea    -0x40(%rbp),%rsi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1060 <G_Printf@plt>
jmp    1294 <Svcmd_LayoutSave_f+0x144>
lea    -0x80(%rbp),%rdi
call   1030 <G_LayoutSave@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Svcmd_LayoutSave_f>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
xor    %eax,%eax
call   1050 <trap_Argc@plt>
cmp    $0x2,%eax
jne    11ef <Svcmd_LayoutSave_f+0x9f>
lea    0x40(%rsp),%rsi
mov    $0x1,%edi
mov    $0x40,%edx
call   1070 <trap_Argv@plt>
mov    0x40(%rsp),%al
test   %al,%al
je     1218 <Svcmd_LayoutSave_f+0xc8>
lea    0x41(%rsp),%rbx
xor    %r14d,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1040 <isalnum@plt>
movzbl -0x1(%rbx),%edx
mov    %ebp,%ecx
test   %rax,%rax
je     11e0 <Svcmd_LayoutSave_f+0x90>
mov    %dl,(%rsp,%r14,1)
movb   $0x0,0x1(%rsp,%rcx,1)
add    $0x1,%rcx
mov    %rcx,%r14
mov    %ecx,%ebp
movzbl (%rbx),%eax
test   %al,%al
je     1208 <Svcmd_LayoutSave_f+0xb8>
add    $0x1,%rbx
cmp    $0x3b,%ebp
jb     11a0 <Svcmd_LayoutSave_f+0x50>
jmp    1208 <Svcmd_LayoutSave_f+0xb8>
nopw   0x0(%rax,%rax,1)
cmp    $0x2d,%dl
je     11b3 <Svcmd_LayoutSave_f+0x63>
cmp    $0x5f,%dl
je     11b3 <Svcmd_LayoutSave_f+0x63>
mov    %rcx,%r14
jmp    11c5 <Svcmd_LayoutSave_f+0x75>
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <G_Printf@plt>
cmpb   $0x0,(%rsp)
je     1218 <Svcmd_LayoutSave_f+0xc8>
mov    %rsp,%rdi
call   1030 <G_LayoutSave@plt>
jmp    122b <Svcmd_LayoutSave_f+0xdb>
lea    0xdfb(%rip),%rdi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1060 <G_Printf@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"usage: layoutsave <name>\0A\00"
@.str.1 = [31 x i8] c"layoutsave: invalid name \22%s\22\0A\00"
define void @Svcmd_LayoutSave_f() {
%1 = alloca [64 x i8]
%2 = alloca [60 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %4
%5 = call i32 (...) @trap_Argc()
%6 = icmp ne i32 %5, 2
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @G_Printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %62
9: ; preds = %0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%11 = call i32 @trap_Argv(i32 1, i8* %10, i32 64)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
store i8* %12, i8** %3
br label %13
13: ; preds = %49, %9
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = icmp ult i64 %20, 59
br label %22
22: ; preds = %18, %13
%23 = phi i1 [ false, %13 ], [ %21, %18 ]
br i1 %23, label %24, label %52
24: ; preds = %22
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = call i64 @isalnum(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %39, label %29
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 45
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = load i8*, i8** %3
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 95
br i1 %38, label %39, label %49
39: ; preds = %34, %29, %24
%40 = load i8*, i8** %3
%41 = load i8, i8* %40
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %44
store i8 %41, i8* %45
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %47
store i8 0, i8* %48
br label %49
49: ; preds = %39, %34
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %3
br label %13
52: ; preds = %22
%53 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%54 = load i8, i8* %53
%55 = icmp ne i8 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %52
%57 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%58 = call i32 (i8*, ...) @G_Printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %57)
br label %62
59: ; preds = %52
%60 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%61 = call i32 @G_LayoutSave(i8* %60)
br label %62
62: ; preds = %59, %56, %7
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"usage: layoutsave <name>\0A\00"
@.str.1 = [31 x i8] c"layoutsave: invalid name \22%s\22\0A\00"
define void @Svcmd_LayoutSave_f() {
%1 = alloca [64 x i8]
%2 = alloca [60 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @trap_Argc()
%6 = icmp eq i32 %5, 2
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @G_Printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %44
9: ; preds = %0
%10 = call i32 @trap_Argv(i32 1, i8* %3, i32 64)
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 0
br i1 %12, label %40, label %13
13: ; preds = %9, %29
%14 = phi i64 [ %30, %29 ], [ 0, %9 ]
%15 = phi i8 [ %33, %29 ], [ %11, %9 ]
%16 = phi i32 [ %31, %29 ], [ 0, %9 ]
%17 = phi i8* [ %32, %29 ], [ %3, %9 ]
%18 = call i64 @isalnum(i8 signext %15)
%19 = icmp eq i64 %18, 0
%20 = load i8, i8* %17
br i1 %19, label %21, label %24
21: ; preds = %13
switch i8 %20, label %22 [
i8 45, label %24
i8 95, label %24
]
22: ; preds = %21
%23 = zext i32 %16 to i64
br label %29
24: ; preds = %13, %21, %21
%25 = add nuw nsw i32 %16, 1
%26 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %14
store i8 %20, i8* %26
%27 = zext i32 %25 to i64
%28 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %22, %24
%30 = phi i64 [ %23, %22 ], [ %27, %24 ]
%31 = phi i32 [ %16, %22 ], [ %25, %24 ]
%32 = getelementptr inbounds i8, i8* %17, i64 1
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
%35 = icmp ult i32 %31, 59
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %13, label %37
37: ; preds = %29
%38 = load i8, i8* %4
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %9, %37
%41 = call i32 (i8*, ...) @G_Printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %44
42: ; preds = %37
%43 = call i32 @G_LayoutSave(i8* %4)
br label %44
44: ; preds = %42, %40, %7
ret void
}