#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*/ log_packet_restart(char *);
int /*<<< orphan*/ log_packet_stop();
int /*<<< orphan*/ log_print(char *, char *);
int sscanf(char *, char *, char *);
scalar_t__ strcasecmp(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
void ui_packetlog(char *cmd) {
  char subcmd[201];
  if (sscanf(cmd, "p %200s", subcmd) != 1)
    goto fail;
  if (strncasecmp(subcmd, "on=", 3) == 0) {
    if (subcmd[strlen(subcmd) - 1] == '\n')
      subcmd[strlen(subcmd) - 1] = 0;
    log_packet_restart(subcmd + 3);
  } else if (strcasecmp(subcmd, "on") == 0)
    log_packet_restart(NULL);
  else if (strcasecmp(subcmd, "off") == 0)
    log_packet_stop();
  return;
fail:
  log_print("ui_packetlog: command \"%s\" malformed", cmd);
}


x86 assembly (clang, -O0):
<ui_packetlog>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xe0(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11a4 <ui_packetlog+0x34>
jmp    1274 <ui_packetlog+0x104>
lea    -0xe0(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1216 <ui_packetlog+0xa6>
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0xe0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1201 <ui_packetlog+0x91>
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    -0xe0(%rbp),%rdi
add    $0x3,%rdi
call   1060 <log_packet_restart@plt>
jmp    126f <ui_packetlog+0xff>
lea    -0xe0(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1241 <ui_packetlog+0xd1>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <log_packet_restart@plt>
jmp    126a <ui_packetlog+0xfa>
lea    -0xe0(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1265 <ui_packetlog+0xf5>
mov    $0x0,%al
call   1090 <log_packet_stop@plt>
jmp    126a <ui_packetlog+0xfa>
jmp    126f <ui_packetlog+0xff>
jmp    1284 <ui_packetlog+0x114>
mov    -0x8(%rbp),%rsi
lea    0xd94(%rip),%rdi
call   1050 <log_print@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ui_packetlog>:
push   %rbx
sub    $0xd0,%rsp
mov    %rdi,%rbx
lea    0xe7e(%rip),%rsi
mov    %rsp,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11dc <ui_packetlog+0x6c>
lea    0xe72(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
je     11ed <ui_packetlog+0x7d>
lea    0xe5a(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1214 <ui_packetlog+0xa4>
lea    0xe49(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    121b <ui_packetlog+0xab>
xor    %eax,%eax
call   1090 <log_packet_stop@plt>
jmp    121b <ui_packetlog+0xab>
lea    0xe30(%rip),%rdi
mov    %rbx,%rsi
call   1050 <log_print@plt>
jmp    121b <ui_packetlog+0xab>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    120d <ui_packetlog+0x9d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0x3(%rsp),%rdi
jmp    1216 <ui_packetlog+0xa6>
xor    %edi,%edi
call   1060 <log_packet_restart@plt>
add    $0xd0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"p %200s\00"
@.str.1 = [4 x i8] c"on=\00"
@.str.2 = [3 x i8] c"on\00"
@.str.3 = [4 x i8] c"off\00"
@.str.4 = [37 x i8] c"ui_packetlog: command \22%s\22 malformed\00"
define void @ui_packetlog(i8* %0) {
%2 = alloca i8*
%3 = alloca [201 x i8]
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%6 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
br label %47
9: ; preds = %1
%10 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%11 = call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %22, %13
%29 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 3
%31 = call i32 @log_packet_restart(i8* %30)
br label %46
32: ; preds = %9
%33 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%34 = call i64 @strcasecmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @log_packet_restart(i8* null)
br label %45
38: ; preds = %32
%39 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%40 = call i64 @strcasecmp(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 (...) @log_packet_stop()
br label %44
44: ; preds = %42, %38
br label %45
45: ; preds = %44, %36
br label %46
46: ; preds = %45, %28
br label %50
47: ; preds = %8
%48 = load i8*, i8** %2
%49 = call i32 @log_print(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %46
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"p %200s\00"
@.str.1 = [4 x i8] c"on=\00"
@.str.2 = [3 x i8] c"on\00"
@.str.3 = [4 x i8] c"off\00"
@.str.4 = [37 x i8] c"ui_packetlog: command \22%s\22 malformed\00"
define void @ui_packetlog(i8* %0) {
%2 = alloca [201 x i8]
%3 = getelementptr inbounds [201 x i8], [201 x i8]* %2, i64 0, i64 0
%4 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %34
6: ; preds = %1
%7 = call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = call i32 @strlen(i8* %3)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [201 x i8], [201 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = call i32 @strlen(i8* %3)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [201 x i8], [201 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %16, %9
%22 = getelementptr inbounds [201 x i8], [201 x i8]* %2, i64 0, i64 3
%23 = call i32 @log_packet_restart(i8* %22)
br label %36
24: ; preds = %6
%25 = call i64 @strcasecmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @log_packet_restart(i8* null)
br label %36
29: ; preds = %24
%30 = call i64 @strcasecmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = call i32 (...) @log_packet_stop()
br label %36
34: ; preds = %1
%35 = call i32 @log_print(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %36
36: ; preds = %21, %29, %32, %27, %34
ret void
}