#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 option {
  char *member_0;
  int member_1;
  char member_3;
  int /*<<< orphan*/ *member_2;
};

/* Variables and functions */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int /*<<< orphan*/ memset(unsigned char *, char, int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_secblk(int, char *, unsigned char *);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int ugci_init(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
scalar_t__ ugci_set_secblk(int, unsigned char *);
int /*<<< orphan*/ usage(int);
int main(int argc, char *argv[]) {
  int rd, id = 0;
  unsigned char vals[14 + 1];
  while (1) {
    int c;
    static struct option long_options[] = {
        {"help", 0, NULL, 'h'},
        {"device", 1, NULL, 'd'},
        {0},
    };
    c = getopt_long(argc, argv, "hd:", long_options, NULL);
    if (c == -1)
      break;
    switch (c) {
    case 'h':
      usage(0);
      break;
    case 'd':
      id = atoi(optarg);
      break;
    }
  }
  if (argc - optind != 1)
    usage(1);
  if (strlen(argv[optind]) > 14) {
    fprintf(stderr, "Security string is too long (max 14 chars)\n");
    exit(1);
  }
  memset(vals, ' ', 14);
  memcpy(vals, argv[optind], strlen(argv[optind]));
  rd = ugci_init(NULL, 0, 1);
  printf("Detected %d UGCI device%s\n", rd, rd == 1 ? "" : "s");
  if (!rd)
    exit(0);
  print_secblk(id, "New Block", vals);
  if (ugci_set_secblk(id, vals)) {
    fprintf(stderr, "UGCI(%d): ", id);
    perror("ugci_set_secblk");
  } else {
    print_secblk(id, "Updated Block", vals);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe11(%rip),%rdx
lea    0x2e8e(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <getopt_long@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    121e <main+0x4e>
jmp    1265 <main+0x95>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x64,%eax
je     124f <main+0x7f>
jmp    1232 <main+0x62>
mov    -0x30(%rbp),%eax
sub    $0x68,%eax
jne    1260 <main+0x90>
jmp    1243 <main+0x73>
xor    %edi,%edi
call   10c0 <usage@plt>
jmp    1260 <main+0x90>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   10e0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11ed <main+0x1d>
mov    -0x8(%rbp),%eax
mov    0x2d71(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
je     1284 <main+0xb4>
mov    $0x1,%edi
call   10c0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d51(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
cmp    $0xe,%eax
jle    12c5 <main+0xf5>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x27(%rbp),%rdi
mov    $0x20,%esi
mov    $0xe,%edx
call   1080 <memset@plt>
lea    -0x27(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2cf5(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2cdf(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   10b0 <memcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <ugci_init@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%ecx
lea    0xd1b(%rip),%rdx
lea    0xcf8(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdx
lea    0xceb(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1367 <main+0x197>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x27(%rbp),%rdx
lea    0xce4(%rip),%rsi
call   1090 <print_secblk@plt>
mov    -0x18(%rbp),%edi
lea    -0x27(%rbp),%rsi
call   1070 <ugci_set_secblk@plt>
cmp    $0x0,%rax
je     13bb <main+0x1eb>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xcc0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    0xcbd(%rip),%rdi
call   10d0 <perror@plt>
jmp    13ce <main+0x1fe>
mov    -0x18(%rbp),%edi
lea    -0x27(%rbp),%rdx
lea    0xcb5(%rip),%rsi
call   1090 <print_secblk@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe1f(%rip),%r15
lea    0x2e9c(%rip),%r12
mov    0x2dfd(%rip),%r13
jmp    1210 <main+0x40>
mov    0x0(%r13),%edi
call   10e0 <atoi@plt>
mov    %eax,%r14d
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1050 <getopt_long@plt>
cmp    $0x68,%eax
je     1240 <main+0x70>
cmp    $0x64,%eax
je     11fd <main+0x2d>
cmp    $0xffffffff,%eax
jne    1210 <main+0x40>
jmp    1249 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
call   10c0 <usage@plt>
jmp    1210 <main+0x40>
mov    0x2d90(%rip),%r15
mov    (%r15),%eax
sub    %eax,%ebp
cmp    $0x1,%ebp
je     1267 <main+0x97>
mov    $0x1,%edi
call   10c0 <usage@plt>
mov    (%r15),%eax
cltq
mov    (%rbx,%rax,8),%rdi
call   1040 <strlen@plt>
cmp    $0xf,%eax
jl     1298 <main+0xc8>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0x9(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
mov    $0xe,%edx
call   1080 <memset@plt>
movslq (%r15),%rax
mov    (%rbx,%rax,8),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10b0 <memcpy@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <ugci_init@plt>
mov    %eax,%ebx
cmp    $0x1,%eax
lea    0xd56(%rip),%rax
lea    0xd6b(%rip),%rdx
cmove  %rax,%rdx
lea    0xd45(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
test   %ebx,%ebx
jne    1309 <main+0x139>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xd49(%rip),%rsi
lea    0x9(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rdx
call   1090 <print_secblk@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <ugci_set_secblk@plt>
test   %rax,%rax
je     135d <main+0x18d>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xd23(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0xd1d(%rip),%rdi
call   10d0 <perror@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xd1a(%rip),%rsi
lea    0x9(%rsp),%rdx
mov    %r14d,%edi
call   1090 <print_secblk@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i32, i8, i32* }
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 104 to i32*) }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 100 to i32*) }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [7 x i8] c"device\00"
@.str.2 = [4 x i8] c"hd:\00"
@optarg = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.3 = [44 x i8] c"Security string is too long (max 14 chars)\0A\00"
@.str.4 = [27 x i8] c"Detected %d UGCI device%s\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [2 x i8] c"s\00"
@.str.7 = [10 x i8] c"New Block\00"
@.str.8 = [11 x i8] c"UGCI(%d): \00"
@.str.9 = [16 x i8] c"ugci_set_secblk\00"
@.str.10 = [14 x i8] c"Updated Block\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [15 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %10
10: ; preds = %2, %24
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt_long(i32 %11, i8** %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %10
br label %25
17: ; preds = %10
%18 = load i32, i32* %9
switch i32 %18, label %24 [
i32 104, label %19
i32 100, label %21
]
19: ; preds = %17
%20 = call i32 @usage(i32 0)
br label %24
21: ; preds = %17
%22 = load i32, i32* @optarg
%23 = call i32 @atoi(i32 %22)
store i32 %23, i32* %7
br label %24
24: ; preds = %17, %21, %19
br label %10
25: ; preds = %16
%26 = load i32, i32* %4
%27 = load i32, i32* @optind
%28 = sub nsw i32 %26, %27
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @usage(i32 1)
br label %32
32: ; preds = %30, %25
%33 = load i8**, i8*** %5
%34 = load i32, i32* @optind
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @strlen(i8* %37)
%39 = icmp sgt i32 %38, 14
br i1 %39, label %40, label %44
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %32
%45 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i8 signext 32, i32 14)
%47 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = load i32, i32* @optind
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = load i32, i32* @optind
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @strlen(i8* %57)
%59 = call i32 @memcpy(i8* %47, i8* %52, i32 %58)
%60 = call i32 @ugci_init(i32* null, i32 0, i32 1)
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = load i32, i32* %6
%63 = icmp eq i32 %62, 1
%64 = zext i1 %63 to i64
%65 = select i1 %63, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%66 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %61, i8* %65)
%67 = load i32, i32* %6
%68 = icmp ne i32 %67, 0
br i1 %68, label %71, label %69
69: ; preds = %44
%70 = call i32 @exit(i32 0)
unreachable
71: ; preds = %44
%72 = load i32, i32* %7
%73 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%74 = call i32 @print_secblk(i32 %72, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %73)
%75 = load i32, i32* %7
%76 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%77 = call i64 @ugci_set_secblk(i32 %75, i8* %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %71
%80 = load i32, i32* @stderr
%81 = load i32, i32* %7
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 %81)
%83 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %88
84: ; preds = %71
%85 = load i32, i32* %7
%86 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%87 = call i32 @print_secblk(i32 %85, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %84, %79
%89 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i8, i32* }
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 0, i8 0, i32* inttoptr (i64 104 to i32*) }, %struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i32 1, i8 0, i32* inttoptr (i64 100 to i32*) }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [7 x i8] c"device\00"
@.str.2 = [4 x i8] c"hd:\00"
@optarg = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.3 = [44 x i8] c"Security string is too long (max 14 chars)\0A\00"
@.str.4 = [27 x i8] c"Detected %d UGCI device%s\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [2 x i8] c"s\00"
@.str.7 = [10 x i8] c"New Block\00"
@.str.8 = [11 x i8] c"UGCI(%d): \00"
@.str.9 = [16 x i8] c"ugci_set_secblk\00"
@.str.10 = [14 x i8] c"Updated Block\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [15 x i8]
%4 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %12, %2
%6 = phi i32 [ %14, %12 ], [ 0, %2 ]
br label %7
7: ; preds = %11, %5
%8 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
switch i32 %8, label %11 [
i32 -1, label %15
i32 104, label %9
i32 100, label %12
]
9: ; preds = %7
%10 = tail call i32 @usage(i32 0)
br label %11
11: ; preds = %9, %7
br label %7
12: ; preds = %7
%13 = load i32, i32* @optarg
%14 = tail call i32 @atoi(i32 %13)
br label %5
15: ; preds = %7
%16 = load i32, i32* @optind
%17 = sub nsw i32 %0, %16
%18 = icmp eq i32 %17, 1
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = tail call i32 @usage(i32 1)
%21 = load i32, i32* @optind
br label %22
22: ; preds = %19, %15
%23 = phi i32 [ %21, %19 ], [ %16, %15 ]
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i32 @strlen(i8* %26)
%28 = icmp sgt i32 %27, 14
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %22
%34 = call i32 @memset(i8* %4, i8 signext 32, i32 14)
%35 = load i32, i32* @optind
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %1, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @memcpy(i8* %4, i8* %38, i32 %39)
%41 = call i32 @ugci_init(i32* null, i32 0, i32 1)
%42 = icmp eq i32 %41, 1
%43 = select i1 %42, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%44 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %41, i8* %43)
%45 = icmp eq i32 %41, 0
br i1 %45, label %46, label %48
46: ; preds = %33
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %33
%49 = call i32 @print_secblk(i32 %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%50 = call i64 @ugci_set_secblk(i32 %6, i8* %4)
%51 = icmp eq i64 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 %6)
%55 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %58
56: ; preds = %48
%57 = call i32 @print_secblk(i32 %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %4)
br label %58
58: ; preds = %56, %52
%59 = call i32 @exit(i32 0)
unreachable
}