#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char const *, char *, int);
scalar_t__ tzj_int(char const *, char *, int *);
scalar_t__ tzj_json(char const *, char *, char const **, int *);
int /*<<< orphan*/ tzj_sprintf(char *, char *, ...);
scalar_t__ tzj_str(char const *, char *, char const **, int *);
void tzj_rpc_example(void) {
  const char *request = "{\"jsonrpc\": \"2.0\", "
                        "\"method\": \"subtract\", "
                        "\"params\": [42, 23], \"id\": \"unknown type\"}";
  char response[128];
  const char *version;
  const char *id;
  int len;
  int a, b;
  printf("RPC Request: %s\n", request);
  if (tzj_str(request, ".jsonrpc", &version, &len) &&
      strncmp(version, "2.0", len) == 0 &&
      tzj_json(request, ".id", &id, &len) &&
      tzj_int(request, ".params[0]", &a) &&
      tzj_int(request, ".params[1]", &b)) {
    tzj_sprintf(response, "{'jsonrpc': '2.0', 'result': %d, 'id': %j}", a - b,
                id, len);
  } else {
    fprintf(stderr, "ERROR: failed to parse request\n");
    tzj_sprintf(response,
                "{'jsonrpc': '2.0', "
                "'error': {'code': -32700, 'message': 'Parse error'}, "
                "'id': null}");
  }
  printf("RPC Response: %s\n", response);
}


x86 assembly (clang, -O0):
<tzj_rpc_example>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    0xe7e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xec3(%rip),%rsi
lea    -0x98(%rbp),%rdx
lea    -0xa4(%rbp),%rcx
call   1060 <tzj_str@plt>
cmp    $0x0,%rax
je     127f <tzj_rpc_example+0x10f>
mov    -0x98(%rbp),%rdi
mov    -0xa4(%rbp),%edx
lea    0xe9b(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    127f <tzj_rpc_example+0x10f>
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
lea    -0xa0(%rbp),%rdx
lea    -0xa4(%rbp),%rcx
call   1080 <tzj_json@plt>
cmp    $0x0,%rax
je     127f <tzj_rpc_example+0x10f>
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
lea    -0xa8(%rbp),%rdx
call   1090 <tzj_int@plt>
cmp    $0x0,%rax
je     127f <tzj_rpc_example+0x10f>
mov    -0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0xac(%rbp),%rdx
call   1090 <tzj_int@plt>
cmp    $0x0,%rax
je     127f <tzj_rpc_example+0x10f>
lea    -0x90(%rbp),%rdi
mov    -0xa8(%rbp),%edx
sub    -0xac(%rbp),%edx
mov    -0xa0(%rbp),%rcx
mov    -0xa4(%rbp),%r8d
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1040 <tzj_sprintf@plt>
jmp    12a9 <tzj_rpc_example+0x139>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1040 <tzj_sprintf@plt>
lea    -0x90(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1050 <printf@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tzj_rpc_example>:
push   %rbx
sub    $0xa0,%rsp
lea    0xed4(%rip),%rdi
lea    0xe7a(%rip),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xecf(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <tzj_str@plt>
test   %rax,%rax
je     11c6 <tzj_rpc_example+0x56>
mov    0x18(%rsp),%rdi
mov    0x4(%rsp),%edx
lea    0xeb1(%rip),%rsi
call   1030 <strncmp@plt>
test   %rax,%rax
je     1208 <tzj_rpc_example+0x98>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xee0(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xef4(%rip),%rsi
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   1040 <tzj_sprintf@plt>
lea    0xf35(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1050 <printf@plt>
add    $0xa0,%rsp
pop    %rbx
ret
lea    0xdf1(%rip),%rdi
lea    0xe5b(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1080 <tzj_json@plt>
test   %rax,%rax
je     11c6 <tzj_rpc_example+0x56>
lea    0xdcf(%rip),%rdi
lea    0xe3d(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1090 <tzj_int@plt>
test   %rax,%rax
je     11c6 <tzj_rpc_example+0x56>
lea    0xdae(%rip),%rdi
lea    0xe27(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1090 <tzj_int@plt>
test   %rax,%rax
je     11c6 <tzj_rpc_example+0x56>
mov    0xc(%rsp),%edx
sub    0x8(%rsp),%edx
mov    0x10(%rsp),%rcx
mov    0x4(%rsp),%r8d
lea    0xe06(%rip),%rsi
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   1040 <tzj_sprintf@plt>
jmp    11ee <tzj_rpc_example+0x7e>

LLVM IR (-O0):
@.str = [83 x i8] c"{\22jsonrpc\22: \222.0\22, \22method\22: \22subtract\22, \22params\22: [42, 23], \22id\22: \22unknown type\22}\00"
@.str.1 = [17 x i8] c"RPC Request: %s\0A\00"
@.str.2 = [9 x i8] c".jsonrpc\00"
@.str.3 = [4 x i8] c"2.0\00"
@.str.4 = [4 x i8] c".id\00"
@.str.5 = [11 x i8] c".params[0]\00"
@.str.6 = [11 x i8] c".params[1]\00"
@.str.7 = [43 x i8] c"{'jsonrpc': '2.0', 'result': %d, 'id': %j}\00"
@stderr = global i32 0
@.str.8 = [32 x i8] c"ERROR: failed to parse request\0A\00"
@.str.9 = [84 x i8] c"{'jsonrpc': '2.0', 'error': {'code': -32700, 'message': 'Parse error'}, 'id': null}\00"
@.str.10 = [18 x i8] c"RPC Response: %s\0A\00"
define void @tzj_rpc_example() {
%1 = alloca i8*
%2 = alloca [128 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8** %1
%8 = load i8*, i8** %1
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %1
%11 = call i64 @tzj_str(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %3, i32* %5)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %38
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = load i8*, i8** %1
%20 = call i64 @tzj_json(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %4, i32* %5)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = load i8*, i8** %1
%24 = call i64 @tzj_int(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i8*, i8** %1
%28 = call i64 @tzj_int(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %7)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = sub nsw i32 %32, %33
%35 = load i8*, i8** %4
%36 = load i32, i32* %5
%37 = call i32 (i8*, i8*, ...) @tzj_sprintf(i8* %31, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %34, i8* %35, i32 %36)
br label %43
38: ; preds = %26, %22, %18, %13, %0
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%42 = call i32 (i8*, i8*, ...) @tzj_sprintf(i8* %41, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.9, i64 0, i64 0))
br label %43
43: ; preds = %38, %30
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%45 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %44)
ret void
}

LLVM IR (-O2):
@.str = [83 x i8] c"{\22jsonrpc\22: \222.0\22, \22method\22: \22subtract\22, \22params\22: [42, 23], \22id\22: \22unknown type\22}\00"
@.str.1 = [17 x i8] c"RPC Request: %s\0A\00"
@.str.2 = [9 x i8] c".jsonrpc\00"
@.str.3 = [4 x i8] c"2.0\00"
@.str.4 = [4 x i8] c".id\00"
@.str.5 = [11 x i8] c".params[0]\00"
@.str.6 = [11 x i8] c".params[1]\00"
@.str.7 = [43 x i8] c"{'jsonrpc': '2.0', 'result': %d, 'id': %j}\00"
@stderr = global i32 0
@.str.8 = [32 x i8] c"ERROR: failed to parse request\0A\00"
@.str.9 = [84 x i8] c"{'jsonrpc': '2.0', 'error': {'code': -32700, 'message': 'Parse error'}, 'id': null}\00"
@.str.10 = [18 x i8] c"RPC Response: %s\0A\00"
define void @tzj_rpc_example() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%8 = bitcast i8** %2 to i8*
%9 = bitcast i8** %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%14 = call i64 @tzj_str(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %2, i32* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %37, label %16
16: ; preds = %0
%17 = load i8*, i8** %2
%18 = load i32, i32* %4
%19 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = call i64 @tzj_json(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %3, i32* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %21
%25 = call i64 @tzj_int(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %37, label %27
27: ; preds = %24
%28 = call i64 @tzj_int(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %6)
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = sub nsw i32 %31, %32
%34 = load i8*, i8** %3
%35 = load i32, i32* %4
%36 = call i32 (i8*, i8*, ...) @tzj_sprintf(i8* %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %33, i8* %34, i32 %35)
br label %41
37: ; preds = %27, %24, %21, %16, %0
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%40 = call i32 (i8*, i8*, ...) @tzj_sprintf(i8* %7, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.9, i64 0, i64 0))
br label %41
41: ; preds = %37, %30
%42 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %7)
ret void
}