#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*/ printf(char *);
__attribute__((no)) int sys_open(int n) {
  int i;
  printf("In sys_open()\n");
  for (i = 0; i < 100; i++) {
    if (i == n)
      return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sys_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xede(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    1162 <sys_open+0x52>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    114f <sys_open+0x3f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1169 <sys_open+0x59>
jmp    1154 <sys_open+0x44>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112e <sys_open+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_open>:
push   %rbx
mov    %edi,%ebx
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x63,%ebx
mov    $0x63,%eax
cmovb  %ebx,%eax
xor    %ecx,%ecx
cmp    $0x10,%eax
jb     1160 <sys_open+0x50>
lea    0x1(%rax),%ecx
mov    %ecx,%edx
and    $0xf,%edx
mov    $0x10,%esi
cmovne %edx,%esi
sub    %esi,%ecx
mov    %ecx,%edx
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xfffffff0,%edx
jne    1150 <sys_open+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %ecx,%ebx
je     116e <sys_open+0x5e>
add    $0x1,%ecx
cmp    $0x64,%ecx
jne    1160 <sys_open+0x50>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"In sys_open()\0A\00"
define i32 @sys_open(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %6
6: ; preds = %16, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 100
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %20
15: ; preds = %9
br label %16
16: ; preds = %15
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %6
19: ; preds = %6
store i32 0, i32* %2
br label %20
20: ; preds = %19, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@str = [14 x i8] c"In sys_open()\00"
define i32 @sys_open(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%3 = call i32 @llvm.umin.i32(i32 %0, i32 99)
%4 = call i32 @llvm.umin.i32(i32 %0, i32 99)
%5 = add nuw nsw i32 %4, 1
%6 = icmp ult i32 %4, 16
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = and i32 %5, 15
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 16, i32 %8
%11 = sub nsw i32 %5, %10
br label %12
12: ; preds = %12, %7
%13 = phi i32 [ 0, %7 ], [ %14, %12 ]
%14 = add nuw i32 %13, 16
%15 = icmp eq i32 %14, %11
br i1 %15, label %16, label %12
16: ; preds = %12, %1
%17 = phi i32 [ 0, %1 ], [ %11, %12 ]
br label %18
18: ; preds = %16, %21
%19 = phi i32 [ %22, %21 ], [ %17, %16 ]
%20 = icmp eq i32 %19, %0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, 100
br i1 %23, label %24, label %18
24: ; preds = %21, %18
%25 = phi i32 [ %3, %18 ], [ 0, %21 ]
ret i32 %25
}