#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*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int getAttenuator(int fd) {
  char cmd[8], response[8];
  sprintf(cmd, "RA;");
  write(fd, cmd, strlen(cmd));
  read(fd, response, 5);
  return response[1] == '1';
}


x86 assembly (clang, -O0):
<getAttenuator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x5,%edx
call   1050 <read@plt>
movsbl -0x13(%rbp),%eax
cmp    $0x31,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAttenuator>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x3b4152,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1050 <read@plt>
xor    %eax,%eax
cmpb   $0x31,0x11(%rsp)
sete   %al
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"RA;\00"
define i32 @getAttenuator(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca [8 x i8]
store i32 %0, i32* %2
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @write(i32 %7, i8* %8, i32 %10)
%12 = load i32, i32* %2
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 5)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 49
%19 = zext i1 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
define i32 @getAttenuator(i32 %0) {
%2 = alloca [8 x i8]
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%6 = bitcast [8 x i8]* %2 to i32*
store i32 3883346, i32* %6
%7 = call i32 @strlen(i8* %4)
%8 = call i32 @write(i32 %0, i8* %4, i32 %7)
%9 = call i32 @read(i32 %0, i8* %5, i32 5)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 49
%13 = zext i1 %12 to i32
ret i32 %13
}