#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*/ adb_close(int);
int /*<<< orphan*/ adb_write(int, char *, int);
int connect_to_console();
int strlen(char *);
int adb_send_emulator_command(int argc, char **argv) {
  int fd, nn;
  fd = connect_to_console();
  if (fd < 0)
    return 1;
  for (nn = 1; nn < argc; nn++) {
    adb_write(fd, argv[nn], strlen(argv[nn]));
    adb_write(fd, (nn == argc - 1) ? "\n" : " ", 1);
  }
  adb_write(fd, "quit\n", sizeof("quit\n") - 1);
  adb_close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<adb_send_emulator_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <connect_to_console@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    116f <adb_send_emulator_command+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1212 <adb_send_emulator_command+0xd2>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ef <adb_send_emulator_command+0xaf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <adb_write@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
lea    0xe36(%rip),%rsi
lea    0xe35(%rip),%rax
cmp    %edx,%ecx
cmove  %rax,%rsi
mov    $0x1,%edx
call   1040 <adb_write@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1176 <adb_send_emulator_command+0x36>
mov    -0x14(%rbp),%edi
lea    0xe09(%rip),%rsi
mov    $0x5,%edx
call   1040 <adb_write@plt>
mov    -0x14(%rbp),%edi
call   1060 <adb_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adb_send_emulator_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
xor    %eax,%eax
call   1050 <connect_to_console@plt>
test   %eax,%eax
js     11e4 <adb_send_emulator_command+0xa4>
mov    %eax,%r13d
cmp    $0x2,%r15d
jl     11c4 <adb_send_emulator_command+0x84>
lea    -0x1(%r15),%r12d
mov    %r15d,%r15d
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbp,8),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <adb_write@plt>
cmp    %rbp,%r12
lea    0xe5d(%rip),%rsi
lea    0xe5c(%rip),%rax
cmove  %rax,%rsi
mov    %r13d,%edi
mov    $0x1,%edx
call   1040 <adb_write@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1180 <adb_send_emulator_command+0x40>
lea    0xe37(%rip),%rsi
mov    %r13d,%edi
mov    $0x5,%edx
call   1040 <adb_write@plt>
mov    %r13d,%edi
call   1060 <adb_close@plt>
xor    %eax,%eax
jmp    11e9 <adb_send_emulator_command+0xa9>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [6 x i8] c"quit\0A\00"
define i32 @adb_send_emulator_command(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @connect_to_console()
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %47
12: ; preds = %2
store i32 1, i32* %7
br label %13
13: ; preds = %39, %12
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = load i32, i32* %6
%19 = load i8**, i8*** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @adb_write(i32 %18, i8* %23, i32 %29)
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = load i32, i32* %4
%34 = sub nsw i32 %33, 1
%35 = icmp eq i32 %32, %34
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%38 = call i32 @adb_write(i32 %31, i8* %37, i32 1)
br label %39
39: ; preds = %17
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %13
42: ; preds = %13
%43 = load i32, i32* %6
%44 = call i32 @adb_write(i32 %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%45 = load i32, i32* %6
%46 = call i32 @adb_close(i32 %45)
store i32 0, i32* %3
br label %47
47: ; preds = %42, %11
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [6 x i8] c"quit\0A\00"
define i32 @adb_send_emulator_command(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @connect_to_console()
%4 = icmp slt i32 %3, 0
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %22
7: ; preds = %5
%8 = add nsw i32 %0, -1
%9 = zext i32 %8 to i64
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 1, %7 ], [ %20, %11 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = tail call i32 @adb_write(i32 %3, i8* %14, i32 %15)
%17 = icmp eq i64 %12, %9
%18 = select i1 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%19 = tail call i32 @adb_write(i32 %3, i8* %18, i32 1)
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %11
22: ; preds = %11, %5
%23 = tail call i32 @adb_write(i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%24 = tail call i32 @adb_close(i32 %3)
br label %25
25: ; preds = %2, %22
%26 = phi i32 [ 0, %22 ], [ 1, %2 ]
ret i32 %26
}