#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 sockaddr_in {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ help(char const *);
int /*<<< orphan*/ printf(char *);
int set_mode(char const *, struct sockaddr_in *, int, char **);
int set_program(char const *, struct sockaddr_in *, int, char **);
scalar_t__ strcmp(char *, char *);
int set(const char *program, struct sockaddr_in *serv_addr, int argc,
        char *argv[]) {
  if (argc < 2) {
    help(program);
    return 1;
  }
  if (strcmp(argv[1], "mode") == 0) {
    return set_mode(program, serv_addr, argc - 1, &argv[1]);
  }
  if (strcmp(argv[1], "program") == 0) {
    return set_program(program, serv_addr, argc - 1, &argv[1]);
  }
  printf("Error : Invalid parameter for command\n");
  help(program);
  return 1;
}


x86 assembly (clang, -O0):
<set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1186 <set+0x36>
mov    -0x10(%rbp),%rdi
call   1070 <help@plt>
movl   $0x1,-0x4(%rbp)
jmp    1224 <set+0xd4>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c7 <set+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x28(%rbp),%rcx
add    $0x8,%rcx
call   1030 <set_mode@plt>
mov    %eax,-0x4(%rbp)
jmp    1224 <set+0xd4>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1208 <set+0xb8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x28(%rbp),%rcx
add    $0x8,%rcx
call   1060 <set_program@plt>
mov    %eax,-0x4(%rbp)
jmp    1224 <set+0xd4>
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <help@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x1,%edx
jle    11a0 <set+0x50>
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r15
mov    0x8(%rcx),%rdi
add    $0x8,%rbx
lea    0xe8a(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b8 <set+0x68>
mov    (%rbx),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d5 <set+0x85>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1070 <help@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <set_mode@plt>
add    $0xffffffff,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <set_program@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [5 x i8] c"mode\00"
@.str.1 = [8 x i8] c"program\00"
@.str.2 = [39 x i8] c"Error : Invalid parameter for command\0A\00"
define i32 @set(i8* %0, %struct.sockaddr_in* %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in*
%8 = alloca i32
%9 = alloca i8**
store i8* %0, i8** %6
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i8*, i8** %6
%14 = call i32 @help(i8* %13)
store i32 1, i32* %5
br label %47
15: ; preds = %4
%16 = load i8**, i8*** %9
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load i8*, i8** %6
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%24 = load i32, i32* %8
%25 = sub nsw i32 %24, 1
%26 = load i8**, i8*** %9
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = call i32 @set_mode(i8* %22, %struct.sockaddr_in* %23, i32 %25, i8** %27)
store i32 %28, i32* %5
br label %47
29: ; preds = %15
%30 = load i8**, i8*** %9
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %29
%36 = load i8*, i8** %6
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%38 = load i32, i32* %8
%39 = sub nsw i32 %38, 1
%40 = load i8**, i8*** %9
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = call i32 @set_program(i8* %36, %struct.sockaddr_in* %37, i32 %39, i8** %41)
store i32 %42, i32* %5
br label %47
43: ; preds = %29
%44 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%45 = load i8*, i8** %6
%46 = call i32 @help(i8* %45)
store i32 1, i32* %5
br label %47
47: ; preds = %43, %35, %21, %12
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@.str = [5 x i8] c"mode\00"
@.str.1 = [8 x i8] c"program\00"
@str = [38 x i8] c"Error : Invalid parameter for command\00"
define i32 @set(i8* %0, %struct.sockaddr_in* %1, i32 %2, i8** %3) {
%5 = icmp slt i32 %2, 2
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @help(i8* %0)
br label %26
8: ; preds = %4
%9 = getelementptr inbounds i8*, i8** %3, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = add nsw i32 %2, -1
%15 = tail call i32 @set_mode(i8* %0, %struct.sockaddr_in* %1, i32 %14, i8** %9)
br label %26
16: ; preds = %8
%17 = load i8*, i8** %9
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = add nsw i32 %2, -1
%22 = tail call i32 @set_program(i8* %0, %struct.sockaddr_in* %1, i32 %21, i8** %9)
br label %26
23: ; preds = %16
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @help(i8* %0)
br label %26
26: ; preds = %23, %20, %13, %6
%27 = phi i32 [ 1, %6 ], [ %15, %13 ], [ %22, %20 ], [ 1, %23 ]
ret i32 %27
}