#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 io_writen(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int Modem_SendCmd(int fd, char *buf, int retry) {
  int i, err;
  for (i = 0; i < retry; i++) {
    err = io_writen(fd, buf, strlen(buf));
    if (err > 0)
      break;
  }
  if (i == retry)
    return -1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<Modem_SendCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118f <Modem_SendCmd+0x6f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <io_writen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    117c <Modem_SendCmd+0x5c>
jmp    118f <Modem_SendCmd+0x6f>
jmp    1181 <Modem_SendCmd+0x61>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <Modem_SendCmd+0x19>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11a7 <Modem_SendCmd+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <Modem_SendCmd+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Modem_SendCmd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
test   %edx,%edx
jle    1166 <Modem_SendCmd+0x46>
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <io_writen@plt>
test   %eax,%eax
jg     1168 <Modem_SendCmd+0x48>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1140 <Modem_SendCmd+0x20>
mov    %r14d,%ebp
jmp    1168 <Modem_SendCmd+0x48>
xor    %ebp,%ebp
xor    %eax,%eax
cmp    %r14d,%ebp
sete   %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Modem_SendCmd(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %24, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @io_writen(i32 %15, i8* %16, i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
br label %27
23: ; preds = %14
br label %24
24: ; preds = %23
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %10
27: ; preds = %22, %10
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -1, i32* %4
br label %33
32: ; preds = %27
store i32 0, i32* %4
br label %33
33: ; preds = %32, %31
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @Modem_SendCmd(i32 %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %13
5: ; preds = %3, %10
%6 = phi i32 [ %11, %10 ], [ 0, %3 ]
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i32 @io_writen(i32 %0, i8* %1, i32 %7)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, %2
br i1 %12, label %13, label %5
13: ; preds = %10, %5, %3
%14 = phi i32 [ 0, %3 ], [ %6, %5 ], [ %2, %10 ]
%15 = icmp eq i32 %14, %2
%16 = sext i1 %15 to i32
ret i32 %16
}