#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 clickos_domid(char *);
char *clickos_read_handler(int, char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int cmd_read_h(int argc, char **argv) {
  int domid;
  char *elem, *attr, *value;
  if (!(domid = strtol(argv[1], NULL, 10)))
    domid = clickos_domid(argv[1]);
  elem = argv[2];
  attr = argv[3];
  ;
  value = clickos_read_handler(domid, elem, attr);
  printf("read(%s/%s) => %s\n", elem, attr, value);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_read_h>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1181 <cmd_read_h+0x41>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <clickos_domid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <clickos_read_handler@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_read_h>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
test   %eax,%eax
jne    1164 <cmd_read_h+0x24>
mov    0x8(%rbx),%rdi
call   1060 <clickos_domid@plt>
mov    0x10(%rbx),%r14
mov    0x18(%rbx),%rbx
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <clickos_read_handler@plt>
lea    0xe80(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"read(%s/%s) => %s\0A\00"
define i32 @cmd_read_h(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @strtol(i8* %11, i32* null, i32 10)
store i32 %12, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @clickos_domid(i8* %17)
store i32 %18, i32* %5
br label %19
19: ; preds = %14, %2
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
store i8* %25, i8** %7
%26 = load i32, i32* %5
%27 = load i8*, i8** %6
%28 = load i8*, i8** %7
%29 = call i8* @clickos_read_handler(i32 %26, i8* %27, i8* %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = load i8*, i8** %8
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %30, i8* %31, i8* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"read(%s/%s) => %s\0A\00"
define i32 @cmd_read_h(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @strtol(i8* nocapture %4, i32* null, i32 10)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = tail call i32 @clickos_domid(i8* %8)
br label %10
10: ; preds = %7, %2
%11 = phi i32 [ %5, %2 ], [ %9, %7 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i8* @clickos_read_handler(i32 %11, i8* %13, i8* %15)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %15, i8* %16)
ret i32 0
}