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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int check_flags(int, char **, float);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *get_user_code_file(char *, int /*<<< orphan*/ *, int);
char *get_user_code_input(char *, int);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print_error_and_quit(float);
int /*<<< orphan*/ print_flags();
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int /*<<< orphan*/ wrong_usage();
int main(int argc, char *argv[]) {
  int max_buf_len = 1000;
  int dev_fd;
  int i;
  int flag_len = 0;
  char user_flags[5];
  FILE *input_fd;
  FILE *output_fd;
  char *user_program = malloc(max_buf_len);
  dev_fd = open("/dev/tcc_dev", O_RDWR);
  if (dev_fd < 0) {
    printf("Couldn't open the device\n");
    exit(-1);
  }
  if (argc < 2) {
    wrong_usage();
  } else if (argc == 2 && strcmp(argv[1], "-h") == 0) {
    print_flags();
    return 0;
  } else {
    int file_index = check_flags(argc, argv, 'u');
    if (file_index > 0) {
      printf("Type your code below:\n");
      user_program = get_user_code_input(user_program, max_buf_len);
    } else {
      file_index = check_flags(argc, argv, 'f');
      if (file_index > 0) {
        input_fd = fopen(argv[file_index + 1], "r");
        if (input_fd < 0) {
          print_error_and_quit('f');
        } else {
          user_program =
              get_user_code_file(user_program, input_fd, max_buf_len);
          fclose(input_fd);
        }
      } else {
        wrong_usage();
      }
    }
    write(dev_fd, user_program, sizeof(user_program));
  }
  return 0;
}


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)
movl   $0x3e8,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    0xde8(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1248 <main+0x68>
lea    0xddc(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jge    125e <main+0x7e>
mov    $0x0,%al
call   1100 <wrong_usage@plt>
jmp    137e <main+0x19e>
cmpl   $0x2,-0x8(%rbp)
jne    1299 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb8(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1299 <main+0xb9>
mov    $0x0,%al
call   1090 <print_flags@plt>
movl   $0x0,-0x4(%rbp)
jmp    1385 <main+0x1a5>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movss  0xd58(%rip),%xmm0
call   10a0 <check_flags@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jle    12db <main+0xfb>
lea    0xd71(%rip),%rdi
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <get_user_code_input@plt>
mov    %rax,-0x40(%rbp)
jmp    1368 <main+0x188>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movss  0xd1a(%rip),%xmm0
call   10a0 <check_flags@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jle    135c <main+0x17c>
mov    -0x10(%rbp),%rax
mov    -0x44(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd35(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jae    133a <main+0x15a>
movss  0xcd4(%rip),%xmm0
call   1070 <print_error_and_quit@plt>
jmp    1357 <main+0x177>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10c0 <get_user_code_file@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1363 <main+0x183>
mov    $0x0,%al
call   1100 <wrong_usage@plt>
jmp    1368 <main+0x188>
mov    -0x18(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
jmp    137e <main+0x19e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x3e8,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     12de <main+0x10e>
cmp    $0x1,%ebp
jg     1217 <main+0x47>
xor    %eax,%eax
call   10f0 <wrong_usage@plt>
jmp    12d1 <main+0x101>
mov    %eax,%r15d
cmp    $0x2,%ebp
jne    1234 <main+0x64>
mov    0x8(%rbx),%rdi
lea    0xdeb(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12b1 <main+0xe1>
movss  0xdc4(%rip),%xmm0
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <check_flags@plt>
test   %eax,%eax
jle    1268 <main+0x98>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1040 <get_user_code_input@plt>
mov    %rax,%r14
jmp    12c1 <main+0xf1>
movss  0xd94(%rip),%xmm0
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <check_flags@plt>
test   %eax,%eax
jle    12ba <main+0xea>
mov    %eax,%eax
mov    0x8(%rbx,%rax,8),%rdi
lea    0xd8c(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x3e8,%edx
call   10b0 <get_user_code_file@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    12c1 <main+0xf1>
xor    %eax,%eax
call   1080 <print_flags@plt>
jmp    12d1 <main+0x101>
xor    %eax,%eax
call   10f0 <wrong_usage@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1050 <write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/tcc_dev\00"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"Couldn't open the device\0A\00"
@.str.2 = [3 x i8] c"-h\00"
@.str.3 = [23 x i8] c"Type your code below:\0A\00"
@.str.4 = [2 x i8] c"r\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 i32
%9 = alloca i32
%10 = alloca [5 x i8]
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1000, i32* %6
store i32 0, i32* %9
%15 = load i32, i32* %6
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %13
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %2
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (...) @wrong_usage()
br label %85
29: ; preds = %24
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 (...) @print_flags()
store i32 0, i32* %3
br label %86
40: ; preds = %32, %29
%41 = load i32, i32* %4
%42 = load i8**, i8*** %5
%43 = call i32 @check_flags(i32 %41, i8** %42, float 1.170000e+02)
store i32 %43, i32* %14
%44 = load i32, i32* %14
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%48 = load i8*, i8** %13
%49 = load i32, i32* %6
%50 = call i8* @get_user_code_input(i8* %48, i32 %49)
store i8* %50, i8** %13
br label %80
51: ; preds = %40
%52 = load i32, i32* %4
%53 = load i8**, i8*** %5
%54 = call i32 @check_flags(i32 %52, i8** %53, float 1.020000e+02)
store i32 %54, i32* %14
%55 = load i32, i32* %14
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %77
57: ; preds = %51
%58 = load i8**, i8*** %5
%59 = load i32, i32* %14
%60 = add nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %58, i64 %61
%63 = load i8*, i8** %62
%64 = call i32* @fopen(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %64, i32** %11
%65 = load i32*, i32** %11
%66 = icmp ult i32* %65, null
br i1 %66, label %67, label %69
67: ; preds = %57
%68 = call i32 @print_error_and_quit(float 1.020000e+02)
br label %76
69: ; preds = %57
%70 = load i8*, i8** %13
%71 = load i32*, i32** %11
%72 = load i32, i32* %6
%73 = call i8* @get_user_code_file(i8* %70, i32* %71, i32 %72)
store i8* %73, i8** %13
%74 = load i32*, i32** %11
%75 = call i32 @fclose(i32* %74)
br label %76
76: ; preds = %69, %67
br label %79
77: ; preds = %51
%78 = call i32 (...) @wrong_usage()
br label %79
79: ; preds = %77, %76
br label %80
80: ; preds = %79, %46
%81 = load i32, i32* %7
%82 = load i8*, i8** %13
%83 = call i32 @write(i32 %81, i8* %82, i32 8)
br label %84
84: ; preds = %80
br label %85
85: ; preds = %84, %27
store i32 0, i32* %3
br label %86
86: ; preds = %85, %38
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/tcc_dev\00"
@O_RDWR = global i32 0
@.str.2 = [3 x i8] c"-h\00"
@.str.4 = [2 x i8] c"r\00"
@str = [22 x i8] c"Type your code below:\00"
@str.5 = [25 x i8] c"Couldn't open the device\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call dereferenceable_or_null(1000) i8* @malloc(i32 1000)
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 (...) @wrong_usage()
br label %45
14: ; preds = %10
%15 = icmp eq i32 %0, 2
br i1 %15, label %16, label %23
16: ; preds = %14
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 (...) @print_flags()
br label %45
23: ; preds = %16, %14
%24 = tail call i32 @check_flags(i32 %0, i8** %1, float 1.170000e+02)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%28 = tail call i8* @get_user_code_input(i8* %3, i32 1000)
br label %42
29: ; preds = %23
%30 = tail call i32 @check_flags(i32 %0, i8** %1, float 1.020000e+02)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = add nuw nsw i32 %30, 1
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%38 = tail call i8* @get_user_code_file(i8* %3, i32* %37, i32 1000)
%39 = tail call i32 @fclose(i32* %37)
br label %42
40: ; preds = %29
%41 = tail call i32 (...) @wrong_usage()
br label %42
42: ; preds = %40, %32, %26
%43 = phi i8* [ %28, %26 ], [ %38, %32 ], [ %3, %40 ]
%44 = tail call i32 @write(i32 %5, i8* %43, i32 8)
br label %45
45: ; preds = %12, %42, %21
ret i32 0
}