#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 */
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_all();
char *call_python(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int hash_it(char const *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
int main(int argc, char **argv) {
  if (argc == 1) {
    add_all();
  } else {
    unsigned user_size = strlen(argv[1]);
    const char *rfid;
    int read_ok = 0;
    printf("Please scan your card.\n");
    while (!read_ok) {
      rfid = call_python("/usr/sbin/rfid_reader");
      if (strcmp(rfid, "") == 0 || strlen(rfid) < 3) {
        printf("RFID read error\n");
      } else {
        read_ok = 1;
      }
    }
    if (strcmp(rfid, "0") == 0) {
      printf("User registration failed.\n");
      return 1;
    }
    uint32_t hash = hash_it(rfid);
    char *hash_text = (char *)malloc(15 * sizeof(char));
    sprintf(hash_text, "%u", hash);
    FILE *users = fopen("/etc/frusers", "a");
    char *command =
        (char *)malloc(sizeof(char) * (2 + user_size + strlen(hash_text)));
    memcpy(command, argv[1], user_size);
    strcat(command, " ");
    strcat(command, hash_text);
    strcat(command, "\n");
    fwrite(command, sizeof(char), strlen(command), users);
    free(command);
    printf("User registered successfully.\n");
    fclose(users);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    120c <main+0x2c>
mov    $0x0,%al
call   1050 <add_all@plt>
jmp    13c2 <main+0x1e2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xdd6(%rip),%rdi
call   1080 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1245 <main+0x65>
jmp    129e <main+0xbe>
lea    0xdcc(%rip),%rdi
call   1100 <call_python@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1281 <main+0xa1>
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x3,%eax
jge    1292 <main+0xb2>
lea    0xda6(%rip),%rdi
call   1080 <printf@plt>
jmp    1299 <main+0xb9>
movl   $0x1,-0x24(%rbp)
jmp    122f <main+0x4f>
mov    -0x20(%rbp),%rdi
lea    0xd96(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12d0 <main+0xf0>
lea    0xd82(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c2 <main+0x1e2>
mov    -0x20(%rbp),%rdi
call   1030 <hash_it@plt>
mov    %eax,-0x28(%rbp)
mov    $0xf,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xd64(%rip),%rsi
call   10e0 <sprintf@plt>
lea    0xd5b(%rip),%rdi
lea    0xd61(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
mov    %eax,%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
call   10a0 <memcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xd11(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10d0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xce0(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
lea    0xcbc(%rip),%rdi
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    11fe <main+0x1e>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <add_all@plt>
jmp    1354 <main+0x174>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
call   1080 <strlen@plt>
mov    %eax,%r14d
lea    0xe1a(%rip),%rdi
lea    0xde5(%rip),%r15
lea    0xe0b(%rip),%r13
lea    0xe54(%rip),%rbp
nopl   0x0(%rax)
call   1060 <puts@plt>
mov    %r15,%rdi
call   1100 <call_python@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
call   1090 <strcmp@plt>
mov    %rbp,%rdi
test   %rax,%rax
je     1230 <main+0x50>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %rbp,%rdi
cmp    $0x3,%eax
jl     1230 <main+0x50>
lea    0xdac(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1343 <main+0x163>
mov    %rbx,%rdi
call   1030 <hash_it@plt>
mov    %eax,%ebx
mov    $0xf,%edi
call   10b0 <malloc@plt>
mov    %rax,%r13
lea    0xd7f(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   10e0 <sprintf@plt>
lea    0xd71(%rip),%rdi
lea    0xd77(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1080 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x2,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%r12),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   10a0 <memcpy@plt>
lea    0xd43(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10d0 <strcat@plt>
lea    0xd2b(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strcat@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10f0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
lea    0xd13(%rip),%rdi
call   1060 <puts@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
xor    %ebx,%ebx
jmp    1354 <main+0x174>
lea    0xd19(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Please scan your card.\0A\00"
@.str.1 = [22 x i8] c"/usr/sbin/rfid_reader\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [17 x i8] c"RFID read error\0A\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [27 x i8] c"User registration failed.\0A\00"
@.str.6 = [3 x i8] c"%u\00"
@.str.7 = [13 x i8] c"/etc/frusers\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [2 x i8] c" \00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [31 x i8] c"User registered successfully.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @add_all()
br label %88
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %6
store i32 0, i32* %8
%22 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %39, %17
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %40
27: ; preds = %23
%28 = call i8* @call_python(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = call i32 @strlen(i8* %33)
%35 = icmp slt i32 %34, 3
br i1 %35, label %36, label %38
36: ; preds = %32, %27
%37 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %39
38: ; preds = %32
store i32 1, i32* %8
br label %39
39: ; preds = %38, %36
br label %23
40: ; preds = %23
%41 = load i8*, i8** %7
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %88
46: ; preds = %40
%47 = load i8*, i8** %7
%48 = call i32 @hash_it(i8* %47)
store i32 %48, i32* %9
%49 = call i64 @malloc(i32 15)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %10
%51 = load i8*, i8** %10
%52 = load i32, i32* %9
%53 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %54, i32** %11
%55 = load i32, i32* %6
%56 = add i32 2, %55
%57 = load i8*, i8** %10
%58 = call i32 @strlen(i8* %57)
%59 = add i32 %56, %58
%60 = zext i32 %59 to i64
%61 = mul i64 1, %60
%62 = trunc i64 %61 to i32
%63 = call i64 @malloc(i32 %62)
%64 = inttoptr i64 %63 to i8*
store i8* %64, i8** %12
%65 = load i8*, i8** %12
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = load i32, i32* %6
%70 = call i32 @memcpy(i8* %65, i8* %68, i32 %69)
%71 = load i8*, i8** %12
%72 = call i32 @strcat(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%73 = load i8*, i8** %12
%74 = load i8*, i8** %10
%75 = call i32 @strcat(i8* %73, i8* %74)
%76 = load i8*, i8** %12
%77 = call i32 @strcat(i8* %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%78 = load i8*, i8** %12
%79 = load i8*, i8** %12
%80 = call i32 @strlen(i8* %79)
%81 = load i32*, i32** %11
%82 = call i32 @fwrite(i8* %78, i32 1, i32 %80, i32* %81)
%83 = load i8*, i8** %12
%84 = call i32 @free(i8* %83)
%85 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0))
%86 = load i32*, i32** %11
%87 = call i32 @fclose(i32* %86)
br label %88
88: ; preds = %44, %46, %15
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"/usr/sbin/rfid_reader\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"0\00"
@.str.6 = [3 x i8] c"%u\00"
@.str.7 = [13 x i8] c"/etc/frusers\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [2 x i8] c" \00"
@.str.10 = [2 x i8] c"\0A\00"
@str = [23 x i8] c"Please scan your card.\00"
@str.12 = [30 x i8] c"User registered successfully.\00"
@str.13 = [26 x i8] c"User registration failed.\00"
@str.14 = [16 x i8] c"RFID read error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @add_all()
br label %46
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
br label %10
10: ; preds = %16, %6
%11 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.14, i64 0, i64 0), %16 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
%13 = tail call i8* @call_python(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10, %17
br label %10
17: ; preds = %10
%18 = tail call i32 @strlen(i8* %13)
%19 = icmp slt i32 %18, 3
br i1 %19, label %16, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
br label %46
25: ; preds = %20
%26 = tail call i32 @hash_it(i8* %13)
%27 = tail call i64 @malloc(i32 15)
%28 = inttoptr i64 %27 to i8*
%29 = tail call i32 @sprintf(i8* dereferenceable(1) %28, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%30 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%31 = add i32 %9, 2
%32 = tail call i32 @strlen(i8* %28)
%33 = add i32 %31, %32
%34 = tail call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
%36 = load i8*, i8** %7
%37 = tail call i32 @memcpy(i8* %35, i8* %36, i32 %9)
%38 = tail call i32 @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%39 = tail call i32 @strcat(i8* %35, i8* %28)
%40 = tail call i32 @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%41 = tail call i32 @strlen(i8* %35)
%42 = tail call i32 @fwrite(i8* %35, i32 1, i32 %41, i32* %30)
%43 = tail call i32 @free(i8* %35)
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.12, i64 0, i64 0))
%45 = tail call i32 @fclose(i32* %30)
br label %46
46: ; preds = %23, %25, %4
%47 = phi i32 [ 0, %4 ], [ 1, %23 ], [ 0, %25 ]
ret i32 %47
}