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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int rev(int);
int main(int argc, char *argv[]) {
  FILE *fp;
  int a, i, r;
  if (argc != 2) {
    printf("Usage: %s [FILE]\n", argv[0]);
    return 1;
  }
  fp = fopen(*++argv, "r");
  while (fscanf(fp, "%d", &a) != EOF) {
    for (i = 0; i < 100; i++) {
      r = rev(a);
      if (r == a)
        break;
      a += r;
    }
    if (i < 100)
      printf("%d %d\n", i, a);
    else
      puts("not found");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1257 <main+0x107>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe55(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <fscanf@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     1250 <main+0x100>
movl   $0x0,-0x20(%rbp)
cmpl   $0x64,-0x20(%rbp)
jge    121c <main+0xcc>
mov    -0x1c(%rbp),%edi
call   1040 <rev@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1205 <main+0xb5>
jmp    121c <main+0xcc>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11df <main+0x8f>
cmpl   $0x64,-0x20(%rbp)
jge    123f <main+0xef>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    124b <main+0xfb>
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
jmp    11b4 <main+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1215 <main+0xc5>
mov    0x8(%rsi),%rdi
lea    0xea3(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe96(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    %rax,%rcx
mov    0x2e53(%rip),%r14
xor    %eax,%eax
cmp    (%r14),%rcx
je     122f <main+0xdf>
lea    0xe6d(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xe6b(%rip),%r13
jmp    11e5 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe50(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
cmp    (%r14),%rax
je     122d <main+0xdd>
mov    0x4(%rsp),%edi
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
call   1040 <rev@plt>
mov    0x4(%rsp),%edi
cmp    %edi,%eax
je     11c0 <main+0x70>
add    %eax,%edi
mov    %edi,0x4(%rsp)
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    11f0 <main+0xa0>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    11d2 <main+0x82>
mov    (%rsi),%rsi
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    122f <main+0xdf>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.3 = [7 x i8] c"%d %d\0A\00"
@.str.4 = [10 x i8] c"not found\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %56
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
br label %22
22: ; preds = %54, %17
%23 = load i32*, i32** %6
%24 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%25 = load i64, i64* @EOF
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %55
27: ; preds = %22
store i32 0, i32* %8
br label %28
28: ; preds = %42, %27
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 100
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = load i32, i32* %7
%33 = call i32 @rev(i32 %32)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = load i32, i32* %7
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %31
br label %45
38: ; preds = %31
%39 = load i32, i32* %9
%40 = load i32, i32* %7
%41 = add nsw i32 %40, %39
store i32 %41, i32* %7
br label %42
42: ; preds = %38
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %28
45: ; preds = %37, %28
%46 = load i32, i32* %8
%47 = icmp slt i32 %46, 100
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %8
%50 = load i32, i32* %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %50)
br label %54
52: ; preds = %45
%53 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
br label %22
55: ; preds = %22
store i32 0, i32* %3
br label %56
56: ; preds = %55, %12
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.3 = [7 x i8] c"%d %d\0A\00"
@.str.4 = [10 x i8] c"not found\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %36
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %36, label %16
16: ; preds = %9, %32
%17 = load i32, i32* %3
br label %18
18: ; preds = %16, %24
%19 = phi i32 [ %17, %16 ], [ %25, %24 ]
%20 = phi i32 [ 0, %16 ], [ %26, %24 ]
%21 = call i32 @rev(i32 %19)
%22 = load i32, i32* %3
%23 = icmp eq i32 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = add nsw i32 %22, %21
store i32 %25, i32* %3
%26 = add nuw nsw i32 %20, 1
%27 = icmp eq i32 %26, 100
br i1 %27, label %30, label %18
28: ; preds = %18
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %21)
br label %32
30: ; preds = %24
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
%33 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%34 = load i64, i64* @EOF
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %16
36: ; preds = %32, %9, %6
%37 = phi i32 [ 1, %6 ], [ 0, %9 ], [ 0, %32 ]
ret i32 %37
}