#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*/ isgraph(int);
int strlen(char *);
int str_is_printable(const char *s) {
  int i, len;
  if (!s || !*s) {
    return 0;
  }
  len = strlen((char *)s);
  for (i = 0; i < len; i++) {
    if (!isgraph((int)s[i])) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<str_is_printable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1144 <str_is_printable+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1150 <str_is_printable+0x30>
movl   $0x0,-0x4(%rbp)
jmp    11af <str_is_printable+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a8 <str_is_printable+0x88>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isgraph@plt>
cmp    $0x0,%eax
jne    1195 <str_is_printable+0x75>
movl   $0x0,-0x4(%rbp)
jmp    11af <str_is_printable+0x8f>
jmp    119a <str_is_printable+0x7a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <str_is_printable+0x43>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_is_printable>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     116b <str_is_printable+0x4b>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     116b <str_is_printable+0x4b>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    116b <str_is_printable+0x4b>
mov    %eax,%r15d
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1040 <isgraph@plt>
test   %eax,%eax
je     1168 <str_is_printable+0x48>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <str_is_printable+0x30>
jmp    116b <str_is_printable+0x4b>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @str_is_printable(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8, %1
store i32 0, i32* %2
br label %35
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %5
store i32 0, i32* %4
br label %16
16: ; preds = %31, %13
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 @isgraph(i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %20
store i32 0, i32* %2
br label %35
30: ; preds = %20
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %16
34: ; preds = %16
store i32 1, i32* %2
br label %35
35: ; preds = %34, %29, %12
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @str_is_printable(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %13
11: ; preds = %13
%12 = icmp eq i64 %20, %10
br i1 %12, label %21, label %13
13: ; preds = %9, %11
%14 = phi i64 [ 0, %9 ], [ %20, %11 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = tail call i32 @isgraph(i32 %17)
%19 = icmp eq i32 %18, 0
%20 = add nuw nsw i64 %14, 1
br i1 %19, label %21, label %11
21: ; preds = %13, %11, %6, %1, %3
%22 = phi i32 [ 0, %3 ], [ 0, %1 ], [ 1, %6 ], [ 0, %13 ], [ 1, %11 ]
ret i32 %22
}