#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned char my_fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void dump_string(FILE *fin, int len) {
  int i;
  fprintf(stderr, "(%d): '", len);
  for (i = 0; i < len; i++) {
    unsigned char c = my_fgetc(fin);
    if (c >= 0x20 && c < 0x80)
      fprintf(stderr, "%c", c);
    else
      fprintf(stderr, "#0x%x#", c);
  }
  fprintf(stderr, "'\n");
}


x86 assembly (clang, -O0):
<dump_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xebe(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d2 <dump_string+0xb2>
mov    -0x8(%rbp),%rdi
call   1030 <my_fgetc@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jl     11a4 <dump_string+0x84>
movzbl -0x11(%rbp),%eax
cmp    $0x80,%eax
jge    11a4 <dump_string+0x84>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
movzbl -0x11(%rbp),%edx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11bf <dump_string+0x9f>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
movzbl -0x11(%rbp),%edx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11c4 <dump_string+0xa4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1150 <dump_string+0x30>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2eab(%rip),%r15
mov    (%r15),%edi
lea    0xec1(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebx,%ebx
jle    1184 <dump_string+0x64>
lea    0xeb5(%rip),%r12
lea    0xeb1(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <my_fgetc@plt>
movzbl %al,%edx
cmp    $0x20,%dl
mov    (%r15),%edi
mov    %r13,%rsi
cmovge %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
jne    1160 <dump_string+0x40>
mov    (%r15),%edi
lea    0xe84(%rip),%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [8 x i8] c"(%d): '\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"x%x#\00"
@.str.3 = [3 x i8] c"'\0A\00"
define void @dump_string(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* @stderr
%8 = load i32, i32* %4
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 0, i32* %5
br label %10
10: ; preds = %35, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = call zeroext i8 @my_fgetc(i32* %15)
store i8 %16, i8* %6
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = icmp sge i32 %18, 32
br i1 %19, label %20, label %29
20: ; preds = %14
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = icmp slt i32 %22, 128
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i8, i8* %6
%27 = zext i8 %26 to i32
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %34
29: ; preds = %20, %14
%30 = load i32, i32* @stderr
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %29, %24
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %10
38: ; preds = %10
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [8 x i8] c"(%d): '\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"x%x#\00"
@.str.3 = [3 x i8] c"'\0A\00"
define void @dump_string(i32* %0, i32 %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %16
6: ; preds = %2, %6
%7 = phi i32 [ %14, %6 ], [ 0, %2 ]
%8 = tail call zeroext i8 @my_fgetc(i32* %0)
%9 = zext i8 %8 to i32
%10 = icmp sgt i8 %8, 31
%11 = load i32, i32* @stderr
%12 = select i1 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* %12, i32 %9)
%14 = add nuw nsw i32 %7, 1
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %6
16: ; preds = %6, %2
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}