#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*/ FILE;

/* Variables and functions */
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void strings(FILE *fp) {
  unsigned char byte;
  int aux = 0;
  int ofs = 0;
  while (fread(&byte, sizeof(unsigned char), 1, fp)) {
    if (aux == 1) {
      putchar('\n');
      printf("%#x  ", ofs);
    } else if (!ofs && isprint(byte))
      printf("0x0  ");
    if (isprint(byte)) {
      putchar(byte);
      aux = 0;
    } else
      aux++;
    ofs++;
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x9(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x0,%rax
je     1211 <strings+0xd1>
cmpl   $0x1,-0x10(%rbp)
jne    11a2 <strings+0x62>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d2 <strings+0x92>
cmpl   $0x0,-0x14(%rbp)
jne    11cd <strings+0x8d>
movzbl -0x9(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     11cd <strings+0x8d>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d2 <strings+0x92>
movzbl -0x9(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     11fa <strings+0xba>
movsbl -0x9(%rbp),%edi
call   1030 <putchar@plt>
movl   $0x0,-0x10(%rbp)
jmp    1203 <strings+0xc3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <strings+0x1a>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     123c <strings+0xfc>
movzbl 0x7(%rsp),%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     118b <strings+0x4b>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x7(%rsp),%bl
movzbl %bl,%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     11a9 <strings+0x69>
movsbl %bl,%edi
call   1030 <putchar@plt>
xor    %r13d,%r13d
jmp    11af <strings+0x6f>
mov    $0x1,%r13d
lea    0x7(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     123c <strings+0xfc>
lea    0xe29(%rip),%r14
lea    0x7(%rsp),%r15
jmp    1201 <strings+0xc1>
xchg   %ax,%ax
add    $0x1,%r13d
add    $0x1,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     123c <strings+0xfc>
cmp    $0x1,%r13d
jne    121d <strings+0xdd>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x7(%rsp),%ebx
movzbl %bl,%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     11e0 <strings+0xa0>
movsbl %bl,%edi
call   1030 <putchar@plt>
xor    %r13d,%r13d
jmp    11e4 <strings+0xa4>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%#x \00"
@.str.1 = [6 x i8] c"0x0 \00"
define void @strings(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %37, %1
%7 = load i32*, i32** %2
%8 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %40
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i32 @putchar(i8 signext 10)
%15 = load i32, i32* %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %27
17: ; preds = %10
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = load i8, i8* %3
%22 = call i64 @isprint(i8 zeroext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %20, %17
br label %27
27: ; preds = %26, %13
%28 = load i8, i8* %3
%29 = call i64 @isprint(i8 zeroext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8, i8* %3
%33 = call i32 @putchar(i8 signext %32)
store i32 0, i32* %4
br label %37
34: ; preds = %27
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %6
40: ; preds = %6
%41 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%#x \00"
@.str.1 = [6 x i8] c"0x0 \00"
define void @strings(i32* nocapture %0) {
%2 = alloca i8
%3 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %41, label %5
5: ; preds = %1
%6 = load i8, i8* %2
%7 = tail call i64 @isprint(i8 zeroext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = load i8, i8* %2
%13 = tail call i64 @isprint(i8 zeroext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @putchar(i8 signext %12)
br label %17
17: ; preds = %11, %15
%18 = phi i32 [ 0, %15 ], [ 1, %11 ]
%19 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %41, label %21
21: ; preds = %17, %36
%22 = phi i32 [ %38, %36 ], [ 1, %17 ]
%23 = phi i32 [ %37, %36 ], [ %18, %17 ]
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = tail call i32 @putchar(i8 signext 10)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %28
28: ; preds = %21, %25
%29 = load i8, i8* %2
%30 = tail call i64 @isprint(i8 zeroext %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @putchar(i8 signext %29)
br label %36
34: ; preds = %28
%35 = add nsw i32 %23, 1
br label %36
36: ; preds = %34, %32
%37 = phi i32 [ 0, %32 ], [ %35, %34 ]
%38 = add nuw nsw i32 %22, 1
%39 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %0)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %21
41: ; preds = %36, %17, %1
%42 = tail call i32 @putchar(i8 signext 10)
ret void
}