#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 */
struct instrument {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ inst_rdstr(struct instrument *, char *, int);
int /*<<< orphan*/ inst_wrtf(struct instrument *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void query_caddr(struct instrument *gd, char *caddr) {
  char buf[128];
  inst_wrtf(gd, "VIEW %s", caddr);
  inst_rdstr(gd, buf, sizeof(buf));
  if (!strncmp(buf, "OPEN   1", 8))
    printf("%s: 0\n", caddr);
  else if (!strncmp(buf, "CLOSED 0", 8))
    printf("%s: 1\n", caddr);
  else
    printf("%s: parse error \n", caddr);
}


x86 assembly (clang, -O0):
<query_caddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe9e(%rip),%rsi
call   1030 <inst_wrtf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1060 <inst_rdstr@plt>
lea    -0x90(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11b2 <query_caddr+0x72>
mov    -0x10(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
jmp    11fd <query_caddr+0xbd>
lea    -0x90(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11e8 <query_caddr+0xa8>
mov    -0x10(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1050 <printf@plt>
jmp    11f8 <query_caddr+0xb8>
mov    -0x10(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
jmp    11fd <query_caddr+0xbd>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_caddr>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea7(%rip),%rsi
mov    %r14,%rdx
call   1030 <inst_wrtf@plt>
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x80,%edx
call   1060 <inst_rdstr@plt>
lea    0xe8d(%rip),%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     11b6 <query_caddr+0x76>
lea    0xe85(%rip),%rsi
mov    %rsp,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
lea    0xe78(%rip),%rax
lea    0xe78(%rip),%rdi
cmove  %rax,%rdi
jmp    11bd <query_caddr+0x7d>
lea    0xe54(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.instrument = type { i32 }
@.str = [8 x i8] c"VIEW %s\00"
@.str.1 = [9 x i8] c"OPEN 1\00"
@.str.2 = [7 x i8] c"%s: 0\0A\00"
@.str.3 = [9 x i8] c"CLOSED 0\00"
@.str.4 = [7 x i8] c"%s: 1\0A\00"
@.str.5 = [18 x i8] c"%s: parse error \0A\00"
define void @query_caddr(%struct.instrument* %0, i8* %1) {
%3 = alloca %struct.instrument*
%4 = alloca i8*
%5 = alloca [128 x i8]
store %struct.instrument* %0, %struct.instrument** %3
store i8* %1, i8** %4
%6 = load %struct.instrument*, %struct.instrument** %3
%7 = load i8*, i8** %4
%8 = call i32 @inst_wrtf(%struct.instrument* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load %struct.instrument*, %struct.instrument** %3
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = call i32 @inst_rdstr(%struct.instrument* %9, i8* %10, i32 128)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%13 = call i32 @strncmp(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %29
18: ; preds = %2
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%20 = call i32 @strncmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %23)
br label %28
25: ; preds = %18
%26 = load i8*, i8** %4
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %22
br label %29
29: ; preds = %28, %15
ret void
}

LLVM IR (-O2):
%struct.instrument = type { i32 }
@.str = [8 x i8] c"VIEW %s\00"
@.str.1 = [9 x i8] c"OPEN 1\00"
@.str.2 = [7 x i8] c"%s: 0\0A\00"
@.str.3 = [9 x i8] c"CLOSED 0\00"
@.str.4 = [7 x i8] c"%s: 1\0A\00"
@.str.5 = [18 x i8] c"%s: parse error \0A\00"
define void @query_caddr(%struct.instrument* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @inst_wrtf(%struct.instrument* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = call i32 @inst_rdstr(%struct.instrument* %0, i8* %4, i32 128)
%7 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0)
br label %13
13: ; preds = %9, %2
%14 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %2 ], [ %12, %9 ]
%15 = call i32 @printf(i8* %14, i8* %1)
ret void
}