#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ putchar(char);
char *xenstore_read(int, char const *);
int read_cmd(int fd, const char *key) {
  char *value;
  char *p;
  value = xenstore_read(fd, key);
  if (value == NULL)
    return 1;
  for (p = value; *p; p++)
    if (*p >= ' ' && *p <= '~' && *p != '\\')
      putchar(*p);
    else {
      putchar('\\');
      switch (*p) {
      case '\t':
        putchar('t');
        break;
      case '\n':
        putchar('n');
        break;
      case '\r':
        putchar('r');
        break;
      case '\\':
        putchar('\\');
        break;
      default:
        if (*p < 010)
          printf("%03o", *p);
        else
          printf("x%02x", *p);
      }
    }
  putchar('\n');
  free(value);
  return 0;
}


x86 assembly (clang, -O0):
<read_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <xenstore_read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1176 <read_cmd+0x36>
movl   $0x1,-0x4(%rbp)
jmp    12d2 <read_cmd+0x192>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     12b8 <read_cmd+0x178>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     11cc <read_cmd+0x8c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jg     11cc <read_cmd+0x8c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     11cc <read_cmd+0x8c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <putchar@plt>
jmp    12a2 <read_cmd+0x162>
mov    $0x5c,%edi
call   1040 <putchar@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x9,%eax
je     1221 <read_cmd+0xe1>
jmp    11ee <read_cmd+0xae>
mov    -0x24(%rbp),%eax
sub    $0xa,%eax
je     1230 <read_cmd+0xf0>
jmp    11ff <read_cmd+0xbf>
mov    -0x24(%rbp),%eax
sub    $0xd,%eax
je     123f <read_cmd+0xff>
jmp    1210 <read_cmd+0xd0>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
je     124e <read_cmd+0x10e>
jmp    125d <read_cmd+0x11d>
mov    $0x74,%edi
call   1040 <putchar@plt>
jmp    129d <read_cmd+0x15d>
mov    $0x6e,%edi
call   1040 <putchar@plt>
jmp    129d <read_cmd+0x15d>
mov    $0x72,%edi
call   1040 <putchar@plt>
jmp    129d <read_cmd+0x15d>
mov    $0x5c,%edi
call   1040 <putchar@plt>
jmp    129d <read_cmd+0x15d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x8,%eax
jge    1285 <read_cmd+0x145>
mov    -0x20(%rbp),%rax
lea    0xd88(%rip),%rdi
movsbl (%rax),%esi
call   1050 <printf@plt>
jmp    1298 <read_cmd+0x158>
mov    -0x20(%rbp),%rax
lea    0xd75(%rip),%rdi
movsbl (%rax),%esi
call   1050 <printf@plt>
jmp    129d <read_cmd+0x15d>
jmp    12a2 <read_cmd+0x162>
jmp    12a7 <read_cmd+0x167>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117e <read_cmd+0x3e>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cmd>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1060 <xenstore_read@plt>
test   %rax,%rax
je     1218 <read_cmd+0xd8>
mov    %rax,%r12
mov    (%rax),%al
test   %al,%al
je     1202 <read_cmd+0xc2>
mov    %r12,%rbx
add    $0x1,%rbx
lea    0xe8f(%rip),%r14
lea    0xe8d(%rip),%r15
jmp    1190 <read_cmd+0x50>
movsbl %al,%edi
nopl   (%rax)
call   1040 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1202 <read_cmd+0xc2>
cmp    $0x20,%al
jl     11a0 <read_cmd+0x60>
cmp    $0x5c,%al
je     11a0 <read_cmd+0x60>
cmp    $0x7f,%al
jne    117a <read_cmd+0x3a>
nopl   0x0(%rax)
mov    $0x5c,%edi
call   1040 <putchar@plt>
movzbl -0x1(%rbx),%eax
movsbl %al,%esi
cmp    $0xc,%esi
jg     11d0 <read_cmd+0x90>
cmp    $0x9,%esi
je     11e1 <read_cmd+0xa1>
cmp    $0xa,%esi
jne    11ef <read_cmd+0xaf>
mov    $0x6e,%edi
jmp    1180 <read_cmd+0x40>
nopw   0x0(%rax,%rax,1)
cmp    $0xd,%esi
je     11e8 <read_cmd+0xa8>
cmp    $0x5c,%esi
jne    11ef <read_cmd+0xaf>
mov    $0x5c,%edi
jmp    1180 <read_cmd+0x40>
mov    $0x74,%edi
jmp    1180 <read_cmd+0x40>
mov    $0x72,%edi
jmp    1180 <read_cmd+0x40>
cmp    $0x7,%al
jg     11f8 <read_cmd+0xb8>
mov    %r14,%rdi
jmp    11fb <read_cmd+0xbb>
mov    %r15,%rdi
call   1050 <printf@plt>
jmp    1185 <read_cmd+0x45>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    121d <read_cmd+0xdd>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%03o\00"
@.str.1 = [6 x i8] c"x%02x\00"
define i32 @read_cmd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = call i8* @xenstore_read(i32 %8, i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %75
14: ; preds = %2
%15 = load i8*, i8** %6
store i8* %15, i8** %7
br label %16
16: ; preds = %68, %14
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %71
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sge i32 %23, 32
br i1 %24, label %25, label %39
25: ; preds = %20
%26 = load i8*, i8** %7
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sle i32 %28, 126
br i1 %29, label %30, label %39
30: ; preds = %25
%31 = load i8*, i8** %7
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 92
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = call i32 @putchar(i8 signext %37)
br label %67
39: ; preds = %30, %25, %20
%40 = call i32 @putchar(i8 signext 92)
%41 = load i8*, i8** %7
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
switch i32 %43, label %52 [
i32 9, label %44
i32 10, label %46
i32 13, label %48
i32 92, label %50
]
44: ; preds = %39
%45 = call i32 @putchar(i8 signext 116)
br label %66
46: ; preds = %39
%47 = call i32 @putchar(i8 signext 110)
br label %66
48: ; preds = %39
%49 = call i32 @putchar(i8 signext 114)
br label %66
50: ; preds = %39
%51 = call i32 @putchar(i8 signext 92)
br label %66
52: ; preds = %39
%53 = load i8*, i8** %7
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp slt i32 %55, 8
br i1 %56, label %57, label %61
57: ; preds = %52
%58 = load i8*, i8** %7
%59 = load i8, i8* %58
%60 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %59)
br label %65
61: ; preds = %52
%62 = load i8*, i8** %7
%63 = load i8, i8* %62
%64 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %63)
br label %65
65: ; preds = %61, %57
br label %66
66: ; preds = %65, %50, %48, %46, %44
br label %67
67: ; preds = %66, %35
br label %68
68: ; preds = %67
%69 = load i8*, i8** %7
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %7
br label %16
71: ; preds = %16
%72 = call i32 @putchar(i8 signext 10)
%73 = load i8*, i8** %6
%74 = call i32 @free(i8* %73)
store i32 0, i32* %3
br label %75
75: ; preds = %71, %13
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str = [5 x i8] c"%03o\00"
@.str.1 = [6 x i8] c"x%02x\00"
define i32 @read_cmd(i32 %0, i8* %1) {
%3 = tail call i8* @xenstore_read(i32 %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %41, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %38, label %8
8: ; preds = %5, %34
%9 = phi i8 [ %36, %34 ], [ %6, %5 ]
%10 = phi i8* [ %35, %34 ], [ %3, %5 ]
%11 = freeze i8 %9
%12 = icmp slt i8 %11, 32
br i1 %12, label %16, label %13
13: ; preds = %8
switch i8 %11, label %14 [
i8 127, label %16
i8 92, label %16
]
14: ; preds = %13
%15 = tail call i32 @putchar(i8 signext %11)
br label %34
16: ; preds = %13, %13, %8
%17 = tail call i32 @putchar(i8 signext 92)
%18 = load i8, i8* %10
%19 = sext i8 %18 to i32
switch i32 %19, label %28 [
i32 9, label %20
i32 10, label %22
i32 13, label %24
i32 92, label %26
]
20: ; preds = %16
%21 = tail call i32 @putchar(i8 signext 116)
br label %34
22: ; preds = %16
%23 = tail call i32 @putchar(i8 signext 110)
br label %34
24: ; preds = %16
%25 = tail call i32 @putchar(i8 signext 114)
br label %34
26: ; preds = %16
%27 = tail call i32 @putchar(i8 signext 92)
br label %34
28: ; preds = %16
%29 = icmp slt i8 %18, 8
br i1 %29, label %30, label %32
30: ; preds = %28
%31 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %18)
br label %34
32: ; preds = %28
%33 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %18)
br label %34
34: ; preds = %14, %30, %32, %26, %24, %22, %20
%35 = getelementptr inbounds i8, i8* %10, i64 1
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %8
38: ; preds = %34, %5
%39 = tail call i32 @putchar(i8 signext 10)
%40 = tail call i32 @free(i8* %3)
br label %41
41: ; preds = %2, %38
%42 = phi i32 [ 0, %38 ], [ 1, %2 ]
ret i32 %42
}