#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int n = 0, opt = 0, i = 0;
  char err = '\0';
  char help_msg[] = "Usage : -n print all number before n \n";
  while ((opt = getopt(argc, argv, "n:")) != -1) {
    switch (opt) {
    case 'n':
      sscanf(optarg, "%d%c", &n, &err);
      if (err != '\0') {
        fprintf(stderr, help_msg);
        return 0;
      }
      break;
    default:
      fprintf(stderr, help_msg);
      return 1;
    }
  }
  if (optind > argc) {
    fprintf(stderr, "No argument after -n %d");
    return 2;
  }
  if (n <= 0) {
    fprintf(stderr, "Incorrect argument");
    return 3;
  }
  for (i = 1; i <= n; ++i)
    fprintf(stderr, "%d\n", i);
  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   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x27,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1228 <main+0xe8>
mov    -0x18(%rbp),%eax
sub    $0x6e,%eax
jne    1203 <main+0xc3>
jmp    11b4 <main+0x74>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x1d(%rbp),%rcx
call   1050 <sscanf@plt>
movsbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
je     11fe <main+0xbe>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cc <main+0x18c>
jmp    1223 <main+0xe3>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x18c>
jmp    1184 <main+0x44>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jle    125d <main+0x11d>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12cc <main+0x18c>
cmpl   $0x0,-0x14(%rbp)
jg     128a <main+0x14a>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    12cc <main+0x18c>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12c5 <main+0x185>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1291 <main+0x151>
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   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
movb   $0x0,0xb(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0xa206e2065726f,%rax
mov    %rax,0x2f(%rsp)
lea    0xea9(%rip),%r14
lea    0xea5(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xb(%rsp),%r13
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
cmp    $0x6e,%eax
jne    11dd <main+0xad>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <sscanf@plt>
cmpb   $0x0,0xb(%rsp)
je     1190 <main+0x60>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
xor    %r14d,%r14d
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1287 <main+0x157>
cmp    $0xffffffff,%eax
jne    120c <main+0xdc>
mov    0x2df7(%rip),%rax
cmp    %ebp,(%rax)
jle    1229 <main+0xf9>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x2,%r14d
jmp    1287 <main+0x157>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%r14d
jmp    1287 <main+0x157>
cmpl   $0x0,0xc(%rsp)
jle    126a <main+0x13a>
xor    %r14d,%r14d
mov    0x2d96(%rip),%r15
lea    0xe19(%rip),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
mov    (%r15),%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    0xc(%rsp),%ebx
jl     1250 <main+0x120>
jmp    1287 <main+0x157>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x3,%r14d
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.help_msg = [39 x i8] c"Usage : -n print all number before n \0A\00"
@.str = [3 x i8] c"n:\00"
@optarg = global i32 0
@.str.1 = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@optind = global i32 0
@.str.2 = [24 x i8] c"No argument after -n %d\00"
@.str.3 = [19 x i8] c"Incorrect argument\00"
@.str.4 = [4 x i8] c"%d\0A\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 i8
%10 = alloca [39 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i8 0, i8* %9
%11 = bitcast [39 x i8]* %10 to i8*
br label %12
12: ; preds = %34, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %7
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %35
17: ; preds = %12
%18 = load i32, i32* %7
switch i32 %18, label %30 [
i32 110, label %19
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = call i32 @sscanf(i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %9)
%22 = load i8, i8* %9
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds [39 x i8], [39 x i8]* %10, i64 0, i64 0
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* %27)
store i32 0, i32* %3
br label %61
29: ; preds = %19
br label %34
30: ; preds = %17
%31 = load i32, i32* @stderr
%32 = getelementptr inbounds [39 x i8], [39 x i8]* %10, i64 0, i64 0
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* %32)
store i32 1, i32* %3
br label %61
34: ; preds = %29
br label %12
35: ; preds = %12
%36 = load i32, i32* @optind
%37 = load i32, i32* %4
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %61
42: ; preds = %35
%43 = load i32, i32* %6
%44 = icmp sle i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %61
48: ; preds = %42
store i32 1, i32* %8
br label %49
49: ; preds = %57, %48
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = icmp sle i32 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i32, i32* %8
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %53
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %49
60: ; preds = %49
store i32 0, i32* %3
br label %61
61: ; preds = %60, %45, %39, %30, %25
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@__const.main.help_msg = [39 x i8] c"Usage : -n print all number before n \0A\00"
@.str = [3 x i8] c"n:\00"
@optarg = global i32 0
@.str.1 = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@optind = global i32 0
@.str.2 = [24 x i8] c"No argument after -n %d\00"
@.str.3 = [19 x i8] c"Incorrect argument\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca [39 x i8]
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
store i8 0, i8* %4
%7 = getelementptr inbounds [39 x i8], [39 x i8]* %5, i64 0, i64 0
br label %8
8: ; preds = %10, %2
%9 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %18 [
i32 -1, label %21
i32 110, label %10
]
10: ; preds = %8
%11 = load i32, i32* @optarg
%12 = call i32 @sscanf(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%13 = load i8, i8* %4
%14 = icmp eq i8 %13, 0
br i1 %14, label %8, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* %7)
br label %40
18: ; preds = %8
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* %7)
br label %40
21: ; preds = %8
%22 = load i32, i32* @optind
%23 = icmp sgt i32 %22, %0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %40
27: ; preds = %21
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %40
33: ; preds = %27, %33
%34 = phi i32 [ %37, %33 ], [ 1, %27 ]
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%37 = add nuw nsw i32 %34, 1
%38 = load i32, i32* %3
%39 = icmp slt i32 %34, %38
br i1 %39, label %33, label %40
40: ; preds = %33, %30, %24, %18, %15
%41 = phi i32 [ 0, %15 ], [ 1, %18 ], [ 2, %24 ], [ 3, %30 ], [ 0, %33 ]
ret i32 %41
}