#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 */
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen_my(char *);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int /*<<< orphan*/);
int sent_cmd(int fd, char *cmd, char *buff, char *dev_type) {
  int n_ret;
  if (!strcmp(dev_type, "UPS")) {
    memset(buff, 0, sizeof(buff));
    n_ret = write(fd, cmd, strlen_my(cmd));
    usleep(700000);
    n_ret = read(fd, buff, 1024);
    return 0;
  } else {
    n_ret = write(fd, cmd, strlen_my(cmd));
    usleep(700000);
    n_ret = read(fd, buff, 333);
    return 0;
  }
}


x86 assembly (clang, -O0):
<sent_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11f2 <sent_cmd+0x92>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen_my@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    $0xaae60,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    123f <sent_cmd+0xdf>
mov    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen_my@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    $0xaae60,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x14d,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sent_cmd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
lea    0xe89(%rip),%rsi
mov    %rcx,%rdi
call   1060 <strcmp@plt>
mov    $0x14d,%ebp
test   %eax,%eax
jne    119c <sent_cmd+0x3c>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    $0x400,%ebp
mov    %rbx,%rdi
call   1070 <strlen_my@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0xaae60,%edi
call   1080 <usleep@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"UPS\00"
define i32 @sent_cmd(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %9
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = call i32 @memset(i8* %15, i32 0, i32 8)
%17 = load i32, i32* %6
%18 = load i8*, i8** %7
%19 = load i8*, i8** %7
%20 = call i32 @strlen_my(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
store i32 %21, i32* %10
%22 = call i32 @usleep(i32 700000)
%23 = load i32, i32* %6
%24 = load i8*, i8** %8
%25 = call i32 @read(i32 %23, i8* %24, i32 1024)
store i32 %25, i32* %10
store i32 0, i32* %5
br label %36
26: ; preds = %4
%27 = load i32, i32* %6
%28 = load i8*, i8** %7
%29 = load i8*, i8** %7
%30 = call i32 @strlen_my(i8* %29)
%31 = call i32 @write(i32 %27, i8* %28, i32 %30)
store i32 %31, i32* %10
%32 = call i32 @usleep(i32 700000)
%33 = load i32, i32* %6
%34 = load i8*, i8** %8
%35 = call i32 @read(i32 %33, i8* %34, i32 333)
store i32 %35, i32* %10
store i32 0, i32* %5
br label %36
36: ; preds = %26, %14
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@.str = [4 x i8] c"UPS\00"
define i32 @sent_cmd(i32 %0, i8* %1, i8* %2, i8* nocapture %3) {
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %3, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @memset(i8* %2, i32 0, i32 8)
br label %9
9: ; preds = %4, %7
%10 = phi i32 [ 1024, %7 ], [ 333, %4 ]
%11 = tail call i32 @strlen_my(i8* %1)
%12 = tail call i32 @write(i32 %0, i8* %1, i32 %11)
%13 = tail call i32 @usleep(i32 700000)
%14 = tail call i32 @read(i32 %0, i8* %2, i32 %10)
ret i32 0
}