#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*/ os_printoutput(char *);
int /*<<< orphan*/ os_shellexec(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int strlen(char *);
void adb_killbypackage(const char *package) {
  char buf[2048] = {0};
  char pidresult[2048] = {0};
  int pidslen = 0;
  int i = 0;
  sprintf(buf, "adb shell \"ps | grep %s | awk '{ print $2 }'\"", package);
  os_shellexec(buf, pidresult, 2048);
  pidslen = strlen(pidresult);
  for (i = 0; i < pidslen; i++) {
    if (pidresult[i] == '\n') {
      pidresult[i] = '\0';
    }
  }
  sprintf(buf, "adb shell \"su -c 'kill %s'\"", pidresult);
  os_printoutput(buf);
}


x86 assembly (clang, -O0):
<adb_killbypackage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
movl   $0x0,-0x1014(%rbp)
movl   $0x0,-0x1018(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x810(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x800,%edx
call   1060 <os_shellexec@plt>
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1014(%rbp)
movl   $0x0,-0x1018(%rbp)
mov    -0x1018(%rbp),%eax
cmp    -0x1014(%rbp),%eax
jge    1236 <adb_killbypackage+0xe6>
movslq -0x1018(%rbp),%rax
movsbl -0x1010(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    121d <adb_killbypackage+0xcd>
movslq -0x1018(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
jmp    1222 <adb_killbypackage+0xd2>
mov    -0x1018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1018(%rbp)
jmp    11e4 <adb_killbypackage+0x94>
lea    -0x810(%rbp),%rdi
lea    -0x1010(%rbp),%rdx
lea    0xde3(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x810(%rbp),%rdi
call   1030 <os_printoutput@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adb_killbypackage>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%rbx
lea    0x800(%rsp),%r14
mov    $0x800,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rsp,%r15
mov    $0x800,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe91(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x800,%edx
call   1060 <os_shellexec@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    138b <adb_killbypackage+0x23b>
mov    %eax,%ecx
cmp    $0x10,%eax
jae    11c8 <adb_killbypackage+0x78>
xor    %eax,%eax
jmp    13c9 <adb_killbypackage+0x279>
mov    %ecx,%eax
and    $0xfffffff0,%eax
xor    %edx,%edx
movdqa 0xe29(%rip),%xmm0
movdqa 0xe31(%rip),%xmm1
jmp    11fd <adb_killbypackage+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x10,%rdx
cmp    %rdx,%rax
je     1386 <adb_killbypackage+0x236>
movq   (%rsp,%rdx,1),%xmm3
movdqa %xmm3,%xmm2
pcmpeqb %xmm0,%xmm2
movd   %xmm2,%esi
test   $0x1,%sil
je     1218 <adb_killbypackage+0xc8>
movb   $0x0,(%rsp,%rdx,1)
movdqa %xmm2,%xmm4
pslld  $0x8,%xmm4
movd   %xmm4,%esi
shr    $0x10,%esi
test   $0x1,%sil
je     1233 <adb_killbypackage+0xe3>
movb   $0x0,0x1(%rsp,%rdx,1)
pshuflw $0x55,%xmm3,%xmm4
pcmpeqb %xmm0,%xmm4
pextrw $0x2,%xmm4,%esi
test   $0x1,%sil
je     124c <adb_killbypackage+0xfc>
movb   $0x0,0x2(%rsp,%rdx,1)
movdqa %xmm2,%xmm4
psllq  $0x18,%xmm4
pextrw $0x3,%xmm4,%esi
test   $0x1,%sil
je     1265 <adb_killbypackage+0x115>
movb   $0x0,0x3(%rsp,%rdx,1)
pshufd $0x55,%xmm3,%xmm3
pcmpeqb %xmm1,%xmm3
pextrw $0x4,%xmm3,%esi
test   $0x1,%sil
je     127e <adb_killbypackage+0x12e>
movb   $0x0,0x4(%rsp,%rdx,1)
movdqa %xmm2,%xmm3
pslldq $0x5,%xmm3
pextrw $0x5,%xmm3,%esi
test   $0x1,%sil
je     1297 <adb_killbypackage+0x147>
movb   $0x0,0x5(%rsp,%rdx,1)
pextrw $0x3,%xmm2,%esi
test   $0x1,%sil
je     12a7 <adb_killbypackage+0x157>
movb   $0x0,0x6(%rsp,%rdx,1)
pslldq $0x7,%xmm2
pextrw $0x7,%xmm2,%esi
test   $0x1,%sil
je     12bc <adb_killbypackage+0x16c>
movb   $0x0,0x7(%rsp,%rdx,1)
movq   0x8(%rsp,%rdx,1),%xmm3
movdqa %xmm3,%xmm2
pcmpeqb %xmm0,%xmm2
movd   %xmm2,%esi
test   $0x1,%sil
je     12d9 <adb_killbypackage+0x189>
movb   $0x0,0x8(%rsp,%rdx,1)
movdqa %xmm2,%xmm4
pslld  $0x8,%xmm4
movd   %xmm4,%esi
shr    $0x10,%esi
test   $0x1,%sil
je     12f4 <adb_killbypackage+0x1a4>
movb   $0x0,0x9(%rsp,%rdx,1)
pshuflw $0x55,%xmm3,%xmm4
pcmpeqb %xmm0,%xmm4
pextrw $0x2,%xmm4,%esi
test   $0x1,%sil
je     130d <adb_killbypackage+0x1bd>
movb   $0x0,0xa(%rsp,%rdx,1)
movdqa %xmm2,%xmm4
psllq  $0x18,%xmm4
pextrw $0x3,%xmm4,%esi
test   $0x1,%sil
je     1326 <adb_killbypackage+0x1d6>
movb   $0x0,0xb(%rsp,%rdx,1)
pshufd $0x55,%xmm3,%xmm3
pcmpeqb %xmm1,%xmm3
pextrw $0x4,%xmm3,%esi
test   $0x1,%sil
je     133f <adb_killbypackage+0x1ef>
movb   $0x0,0xc(%rsp,%rdx,1)
movdqa %xmm2,%xmm3
pslldq $0x5,%xmm3
pextrw $0x5,%xmm3,%esi
test   $0x1,%sil
je     1358 <adb_killbypackage+0x208>
movb   $0x0,0xd(%rsp,%rdx,1)
pextrw $0x3,%xmm2,%esi
test   $0x1,%sil
je     1368 <adb_killbypackage+0x218>
movb   $0x0,0xe(%rsp,%rdx,1)
pslldq $0x7,%xmm2
pextrw $0x7,%xmm2,%esi
test   $0x1,%sil
je     11f0 <adb_killbypackage+0xa0>
movb   $0x0,0xf(%rsp,%rdx,1)
jmp    11f0 <adb_killbypackage+0xa0>
cmp    %rcx,%rax
jne    13c9 <adb_killbypackage+0x279>
lea    0xcbc(%rip),%rsi
lea    0x800(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <os_printoutput@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %rax,%rcx
je     138b <adb_killbypackage+0x23b>
cmpb   $0xa,(%rsp,%rax,1)
jne    13c0 <adb_killbypackage+0x270>
movb   $0x0,(%rsp,%rax,1)
jmp    13c0 <adb_killbypackage+0x270>

LLVM IR (-O0):
@.str = [46 x i8] c"adb shell \22ps | grep %s | awk '{ print $2 }'\22\00"
@.str.1 = [28 x i8] c"adb shell \22su -c 'kill %s'\22\00"
define void @adb_killbypackage(i8* %0) {
%2 = alloca i8*
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = bitcast [2048 x i8]* %3 to i8*
%8 = bitcast [2048 x i8]* %4 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%14 = call i32 @os_shellexec(i8* %12, i8* %13, i32 2048)
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %5
store i32 0, i32* %6
br label %17
17: ; preds = %33, %1
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %28, %21
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %17
36: ; preds = %17
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%41 = call i32 @os_printoutput(i8* %40)
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c"adb shell \22ps | grep %s | awk '{ print $2 }'\22\00"
@.str.1 = [28 x i8] c"adb shell \22su -c 'kill %s'\22\00"
define void @adb_killbypackage(i8* %0) {
%2 = alloca [2048 x i8]
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @os_shellexec(i8* %4, i8* %5, i32 2048)
%8 = call i32 @strlen(i8* %5)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %119
10: ; preds = %1
%11 = zext i32 %8 to i64
%12 = icmp ult i32 %8, 16
br i1 %12, label %108, label %13
13: ; preds = %10
%14 = and i64 %11, 4294967280
br label %15
15: ; preds = %103, %13
%16 = phi i64 [ 0, %13 ], [ %104, %103 ]
%17 = or i64 %16, 8
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %16
%19 = bitcast i8* %18 to <8 x i8>*
%20 = load <8 x i8>, <8 x i8>* %19
%21 = getelementptr inbounds i8, i8* %18, i64 8
%22 = bitcast i8* %21 to <8 x i8>*
%23 = load <8 x i8>, <8 x i8>* %22
%24 = icmp eq <8 x i8> %20, <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
%25 = icmp eq <8 x i8> %23, <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
%26 = extractelement <8 x i1> %24, i64 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %28
br label %29
29: ; preds = %27, %15
%30 = extractelement <8 x i1> %24, i64 1
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = or i64 %16, 1
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %31, %29
%35 = extractelement <8 x i1> %24, i64 2
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = or i64 %16, 2
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %36, %34
%40 = extractelement <8 x i1> %24, i64 3
br i1 %40, label %41, label %44
41: ; preds = %39
%42 = or i64 %16, 3
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %41, %39
%45 = extractelement <8 x i1> %24, i64 4
br i1 %45, label %46, label %49
46: ; preds = %44
%47 = or i64 %16, 4
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %47
store i8 0, i8* %48
br label %49
49: ; preds = %46, %44
%50 = extractelement <8 x i1> %24, i64 5
br i1 %50, label %51, label %54
51: ; preds = %49
%52 = or i64 %16, 5
%53 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %52
store i8 0, i8* %53
br label %54
54: ; preds = %51, %49
%55 = extractelement <8 x i1> %24, i64 6
br i1 %55, label %56, label %59
56: ; preds = %54
%57 = or i64 %16, 6
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %57
store i8 0, i8* %58
br label %59
59: ; preds = %56, %54
%60 = extractelement <8 x i1> %24, i64 7
br i1 %60, label %61, label %64
61: ; preds = %59
%62 = or i64 %16, 7
%63 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %62
store i8 0, i8* %63
br label %64
64: ; preds = %61, %59
%65 = extractelement <8 x i1> %25, i64 0
br i1 %65, label %66, label %68
66: ; preds = %64
%67 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %67
br label %68
68: ; preds = %66, %64
%69 = extractelement <8 x i1> %25, i64 1
br i1 %69, label %70, label %73
70: ; preds = %68
%71 = or i64 %16, 9
%72 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %71
store i8 0, i8* %72
br label %73
73: ; preds = %70, %68
%74 = extractelement <8 x i1> %25, i64 2
br i1 %74, label %75, label %78
75: ; preds = %73
%76 = or i64 %16, 10
%77 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %76
store i8 0, i8* %77
br label %78
78: ; preds = %75, %73
%79 = extractelement <8 x i1> %25, i64 3
br i1 %79, label %80, label %83
80: ; preds = %78
%81 = or i64 %16, 11
%82 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %81
store i8 0, i8* %82
br label %83
83: ; preds = %80, %78
%84 = extractelement <8 x i1> %25, i64 4
br i1 %84, label %85, label %88
85: ; preds = %83
%86 = or i64 %16, 12
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %86
store i8 0, i8* %87
br label %88
88: ; preds = %85, %83
%89 = extractelement <8 x i1> %25, i64 5
br i1 %89, label %90, label %93
90: ; preds = %88
%91 = or i64 %16, 13
%92 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %91
store i8 0, i8* %92
br label %93
93: ; preds = %90, %88
%94 = extractelement <8 x i1> %25, i64 6
br i1 %94, label %95, label %98
95: ; preds = %93
%96 = or i64 %16, 14
%97 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %96
store i8 0, i8* %97
br label %98
98: ; preds = %95, %93
%99 = extractelement <8 x i1> %25, i64 7
br i1 %99, label %100, label %103
100: ; preds = %98
%101 = or i64 %16, 15
%102 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %101
store i8 0, i8* %102
br label %103
103: ; preds = %100, %98
%104 = add nuw i64 %16, 16
%105 = icmp eq i64 %104, %14
br i1 %105, label %106, label %15
106: ; preds = %103
%107 = icmp eq i64 %14, %11
br i1 %107, label %119, label %108
108: ; preds = %10, %106
%109 = phi i64 [ 0, %10 ], [ %14, %106 ]
br label %110
110: ; preds = %108, %116
%111 = phi i64 [ %117, %116 ], [ %109, %108 ]
%112 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %111
%113 = load i8, i8* %112
%114 = icmp eq i8 %113, 10
br i1 %114, label %115, label %116
115: ; preds = %110
store i8 0, i8* %112
br label %116
116: ; preds = %110, %115
%117 = add nuw nsw i64 %111, 1
%118 = icmp eq i64 %117, %11
br i1 %118, label %119, label %110
119: ; preds = %116, %106, %1
%120 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%121 = call i32 @os_printoutput(i8* %4)
ret void
}