#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 */
struct ip_usbph {
  int dummy;
};
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ argv_free(int, char **);
int argv_from(char *, int *, char ***);
int command(struct ip_usbph **, int, char **);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ ip_usbph_release(struct ip_usbph *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rc_save(struct ip_usbph *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  struct ip_usbph *ph = NULL;
  int err;
  if (argc < 2) {
    usage(argv[0]);
  }
  if (argc == 2 &&
      (strcmp(argv[1], "shell") == 0 || strcmp(argv[1], "pipe") == 0)) {
    int pipe_mode = (strcmp(argv[1], "pipe") == 0);
    for (;;) {
      char buff[256];
      char *s;
      if (!pipe_mode) {
        printf("ip-usbph> ");
      };
      buff[0] = 0;
      s = fgets(buff, sizeof(buff), stdin);
      if (s == NULL || buff[0] == 0) {
        return EXIT_SUCCESS;
      }
      err = argv_from(buff, &argc, &argv);
      if (err < 0) {
        return EXIT_FAILURE;
      }
      if (argc == 0 || strcmp(argv[0], "exit") == 0) {
        return EXIT_SUCCESS;
      }
      err = command(&ph, argc, argv);
      if (err < 0) {
        fprintf(stderr, "%s\n", strerror(-err));
      }
      argv_free(argc, argv);
    }
  } else {
    err = command(&ph, argc - 1, &argv[1]);
  }
  if (ph != NULL) {
    rc_save(ph);
    ip_usbph_release(ph);
  }
  return (err == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e7 <main+0x37>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1383 <main+0x1d3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe00(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     122d <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde8(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1383 <main+0x1d3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdca(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1266 <main+0xb6>
lea    0xdaa(%rip),%rdi
call   1050 <printf@plt>
movb   $0x0,-0x120(%rbp)
lea    -0x120(%rbp),%rdi
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     12ac <main+0xfc>
movsbl -0x120(%rbp),%eax
cmp    $0x0,%eax
jne    12bd <main+0x10d>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13f0 <main+0x240>
lea    -0x120(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10b0 <argv_from@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12ef <main+0x13f>
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13f0 <main+0x240>
cmpl   $0x0,-0x8(%rbp)
je     1316 <main+0x166>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd0f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1327 <main+0x177>
mov    0x2cab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13f0 <main+0x240>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
call   1040 <command@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1372 <main+0x1c2>
mov    0x2c8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
xor    %edi,%edi
sub    -0x1c(%rbp),%edi
call   10d0 <strerror@plt>
mov    -0x12c(%rbp),%edi
mov    %rax,%rdx
lea    0xcae(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <argv_free@plt>
jmp    1250 <main+0xa0>
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%rdx
add    $0x8,%rdx
lea    -0x18(%rbp),%rdi
call   1040 <command@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     13ba <main+0x20a>
mov    -0x18(%rbp),%rdi
call   1030 <rc_save@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <ip_usbph_release@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    13d8 <main+0x228>
mov    0x2bfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
jmp    13e7 <main+0x237>
mov    0x2bf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
mov    -0x130(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,0x4(%rsp)
mov    %rsi,0x10(%rsp)
movq   $0x0,0x8(%rsp)
cmp    $0x1,%edi
jg     11e7 <main+0x37>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
jmp    1216 <main+0x66>
cmp    $0x2,%ebp
jne    1216 <main+0x66>
mov    0x8(%rbx),%rdi
lea    0xe09(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     125b <main+0xab>
mov    0x8(%rbx),%rdi
lea    0xdfa(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     125b <main+0xab>
add    $0xffffffff,%ebp
add    $0x8,%rbx
lea    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1040 <command@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1247 <main+0x97>
call   1030 <rc_save@plt>
mov    0x8(%rsp),%rdi
call   10a0 <ip_usbph_release@plt>
test   %ebx,%ebx
jne    136b <main+0x1bb>
mov    0x2d72(%rip),%rax
jmp    1372 <main+0x1c2>
mov    0x8(%rbx),%rdi
lea    0xda0(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%r15
mov    0x2d73(%rip),%rbx
lea    0x20(%rsp),%rbp
lea    0x4(%rsp),%r12
lea    0x10(%rsp),%r14
lea    0xd8b(%rip),%r13
mov    %rax,0x18(%rsp)
jmp    12ae <main+0xfe>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x4(%rsp),%edi
mov    0x10(%rsp),%rsi
call   1080 <argv_free@plt>
test   %r15,%r15
je     12bf <main+0x10f>
lea    0xd51(%rip),%rdi
call   1050 <printf@plt>
movb   $0x0,0x20(%rsp)
mov    (%rbx),%edx
mov    %rbp,%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     124f <main+0x9f>
cmpb   $0x0,0x20(%rsp)
je     124f <main+0x9f>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10b0 <argv_from@plt>
test   %eax,%eax
js     136b <main+0x1bb>
cmpl   $0x0,0x4(%rsp)
je     124f <main+0x9f>
mov    0x10(%rsp),%rax
mov    (%rax),%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     124f <main+0x9f>
mov    0x4(%rsp),%esi
mov    0x10(%rsp),%rdx
lea    0x8(%rsp),%rdi
call   1040 <command@plt>
test   %eax,%eax
jns    12a0 <main+0xf0>
mov    %rbp,%r15
mov    0x2c96(%rip),%rcx
mov    (%rcx),%ebp
neg    %eax
mov    %eax,%edi
call   10d0 <strerror@plt>
mov    %ebp,%edi
mov    %r15,%rbp
mov    0x18(%rsp),%r15
lea    0xcbd(%rip),%rsi
mov    %rax,%rdx
call   1090 <fprintf@plt>
jmp    12a0 <main+0xf0>
mov    0x2c5e(%rip),%rax
mov    (%rax),%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip_usbph = type { i32 }
@.str = [6 x i8] c"shell\00"
@.str.1 = [5 x i8] c"pipe\00"
@.str.2 = [11 x i8] c"ip-usbph> \00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"exit\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ip_usbph*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.ip_usbph* null, %struct.ip_usbph** %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @usage(i8* %16)
br label %18
18: ; preds = %13, %2
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %93
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %93
33: ; preds = %27, %21
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
store i32 %39, i32* %8
br label %40
40: ; preds = %89, %33
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
store i8 0, i8* %46
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%48 = load i32, i32* @stdin
%49 = call i8* @fgets(i8* %47, i32 256, i32 %48)
store i8* %49, i8** %10
%50 = load i8*, i8** %10
%51 = icmp eq i8* %50, null
br i1 %51, label %57, label %52
52: ; preds = %45
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52, %45
%58 = load i32, i32* @EXIT_SUCCESS
store i32 %58, i32* %3
br label %116
59: ; preds = %52
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%61 = call i32 @argv_from(i8* %60, i32* %4, i8*** %5)
store i32 %61, i32* %7
%62 = load i32, i32* %7
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %3
br label %116
66: ; preds = %59
%67 = load i32, i32* %4
%68 = icmp eq i32 %67, 0
br i1 %68, label %75, label %69
69: ; preds = %66
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 0
%72 = load i8*, i8** %71
%73 = call i64 @strcmp(i8* %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %69, %66
%76 = load i32, i32* @EXIT_SUCCESS
store i32 %76, i32* %3
br label %116
77: ; preds = %69
%78 = load i32, i32* %4
%79 = load i8**, i8*** %5
%80 = call i32 @command(%struct.ip_usbph** %6, i32 %78, i8** %79)
store i32 %80, i32* %7
%81 = load i32, i32* %7
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %89
83: ; preds = %77
%84 = load i32, i32* @stderr
%85 = load i32, i32* %7
%86 = sub nsw i32 0, %85
%87 = call i8* @strerror(i32 %86)
%88 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %83, %77
%90 = load i32, i32* %4
%91 = load i8**, i8*** %5
%92 = call i32 @argv_free(i32 %90, i8** %91)
br label %40
93: ; preds = %27, %18
%94 = load i32, i32* %4
%95 = sub nsw i32 %94, 1
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 1
%98 = call i32 @command(%struct.ip_usbph** %6, i32 %95, i8** %97)
store i32 %98, i32* %7
br label %99
99: ; preds = %93
%100 = load %struct.ip_usbph*, %struct.ip_usbph** %6
%101 = icmp ne %struct.ip_usbph* %100, null
br i1 %101, label %102, label %107
102: ; preds = %99
%103 = load %struct.ip_usbph*, %struct.ip_usbph** %6
%104 = call i32 @rc_save(%struct.ip_usbph* %103)
%105 = load %struct.ip_usbph*, %struct.ip_usbph** %6
%106 = call i32 @ip_usbph_release(%struct.ip_usbph* %105)
br label %107
107: ; preds = %102, %99
%108 = load i32, i32* %7
%109 = icmp eq i32 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %107
%111 = load i32, i32* @EXIT_SUCCESS
br label %114
112: ; preds = %107
%113 = load i32, i32* @EXIT_FAILURE
br label %114
114: ; preds = %112, %110
%115 = phi i32 [ %111, %110 ], [ %113, %112 ]
store i32 %115, i32* %3
br label %116
116: ; preds = %114, %75, %64, %57
%117 = load i32, i32* %3
ret i32 %117
}

LLVM IR (-O2):
%struct.ip_usbph = type { i32 }
@.str = [6 x i8] c"shell\00"
@.str.1 = [5 x i8] c"pipe\00"
@.str.2 = [11 x i8] c"ip-usbph> \00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"exit\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.ip_usbph*
%6 = alloca [256 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = bitcast %struct.ip_usbph** %5 to i8*
store %struct.ip_usbph* null, %struct.ip_usbph** %5
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @usage(i8* %10)
br label %66
12: ; preds = %2
%13 = icmp eq i32 %0, 2
br i1 %13, label %14, label %66
14: ; preds = %12
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %66
23: ; preds = %19, %14
%24 = load i8*, i8** %15
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
br label %28
28: ; preds = %62, %23
br i1 %26, label %31, label %29
29: ; preds = %28
%30 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %28
store i8 0, i8* %27
%32 = load i32, i32* @stdin
%33 = call i8* @fgets(i8* %27, i32 256, i32 %32)
%34 = icmp eq i8* %33, null
%35 = load i8, i8* %27
%36 = icmp eq i8 %35, 0
%37 = select i1 %34, i1 true, i1 %36
br i1 %37, label %59, label %38
38: ; preds = %31
%39 = call i32 @argv_from(i8* %27, i32* %3, i8*** %4)
%40 = icmp slt i32 %39, 0
br i1 %40, label %59, label %41
41: ; preds = %38
%42 = load i32, i32* %3
%43 = icmp eq i32 %42, 0
br i1 %43, label %59, label %44
44: ; preds = %41
%45 = load i8**, i8*** %4
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %59, label %49
49: ; preds = %44
%50 = load i32, i32* %3
%51 = load i8**, i8*** %4
%52 = call i32 @command(%struct.ip_usbph** %5, i32 %50, i8** %51)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = sub nsw i32 0, %52
%57 = call i8* @strerror(i32 %56)
%58 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %62
59: ; preds = %41, %44, %38, %31
%60 = phi i32* [ @EXIT_SUCCESS, %31 ], [ @EXIT_FAILURE, %38 ], [ @EXIT_SUCCESS, %44 ], [ @EXIT_SUCCESS, %41 ]
%61 = load i32, i32* %60
br label %81
62: ; preds = %49, %54
%63 = load i32, i32* %3
%64 = load i8**, i8*** %4
%65 = call i32 @argv_free(i32 %63, i8** %64)
br label %28
66: ; preds = %9, %19, %12
%67 = add nsw i32 %0, -1
%68 = getelementptr inbounds i8*, i8** %1, i64 1
%69 = call i32 @command(%struct.ip_usbph** %5, i32 %67, i8** %68)
%70 = load %struct.ip_usbph*, %struct.ip_usbph** %5
%71 = icmp eq %struct.ip_usbph* %70, null
br i1 %71, label %76, label %72
72: ; preds = %66
%73 = call i32 @rc_save(%struct.ip_usbph* %70)
%74 = load %struct.ip_usbph*, %struct.ip_usbph** %5
%75 = call i32 @ip_usbph_release(%struct.ip_usbph* %74)
br label %76
76: ; preds = %72, %66
%77 = icmp eq i32 %69, 0
%78 = load i32, i32* @EXIT_SUCCESS
%79 = load i32, i32* @EXIT_FAILURE
%80 = select i1 %77, i32 %78, i32 %79
br label %81
81: ; preds = %59, %76
%82 = phi i32 [ %80, %76 ], [ %61, %59 ]
ret i32 %82
}