#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*/ *strchr(char *, int /*<<< orphan*/);
int strlen(char *);
char *validatePrintSpecification(char *spec) {
  int i = 0;
  char *ptr = spec;
  for (i = 0; i < strlen(spec); i++) {
    if (strchr("ahHtTrRpwgdDuUi", *ptr++) == NULL) {
      return NULL;
    }
  }
  return spec;
}


x86 assembly (clang, -O0):
<validatePrintSpecification>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11a6 <validatePrintSpecification+0x86>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%esi
lea    0xe89(%rip),%rdi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1193 <validatePrintSpecification+0x73>
movq   $0x0,-0x8(%rbp)
jmp    11ae <validatePrintSpecification+0x8e>
jmp    1198 <validatePrintSpecification+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <validatePrintSpecification+0x22>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validatePrintSpecification>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1167 <validatePrintSpecification+0x47>
lea    0xec8(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1164 <validatePrintSpecification+0x44>
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0x1,%rbx
cmp    %eax,%ebx
jl     1140 <validatePrintSpecification+0x20>
jmp    1167 <validatePrintSpecification+0x47>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"ahHtTrRpwgdDuUi\00"
define i8* @validatePrintSpecification(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
store i32 0, i32* %4
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
%17 = call i32* @strchr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %12
store i8* null, i8** %2
br label %26
20: ; preds = %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %7
24: ; preds = %7
%25 = load i8*, i8** %3
store i8* %25, i8** %2
br label %26
26: ; preds = %24, %19
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [16 x i8] c"ahHtTrRpwgdDuUi\00"
define i8* @validatePrintSpecification(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1, %11
%5 = phi i8* [ %12, %11 ], [ %0, %1 ]
%6 = phi i32 [ %13, %11 ], [ 0, %1 ]
%7 = load i8, i8* %5
%8 = sext i8 %7 to i32
%9 = tail call i32* @strchr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = add nuw nsw i32 %6, 1
%14 = tail call i32 @strlen(i8* %0)
%15 = icmp slt i32 %13, %14
br i1 %15, label %4, label %16
16: ; preds = %4, %11, %1
%17 = phi i8* [ %0, %1 ], [ %0, %11 ], [ null, %4 ]
ret i8* %17
}