#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 */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *,
                          unsigned int *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ puts(char *);
int trova_targhet(unsigned int **tabella, int j, int targhet) {
  int i = -1;
  FILE *file_tabelle;
  unsigned int numero_righe;
  unsigned int numero_colonne;
  unsigned int indice_righe;
  file_tabelle = fopen("tabelle.txt", "r");
  if (file_tabelle != NULL) {
    fscanf(file_tabelle, "%u %u", &numero_righe, &numero_colonne);
  }
  if (j <= numero_colonne) {
    indice_righe = 0;
    while (indice_righe < numero_righe) {
      if (tabella[indice_righe][j] == targhet) {
        i = indice_righe;
        indice_righe = numero_righe;
      } else
        printf("%d\n", tabella[indice_righe][j]);
      indice_righe++;
    }
  } else {
    puts("numero colonna inesistente");
  }
  return (i = +1);
}


x86 assembly (clang, -O0):
<trova_targhet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    0xea0(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1193 <trova_targhet+0x53>
mov    -0x20(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1050 <fscanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x28(%rbp),%eax
ja     120f <trova_targhet+0xcf>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    120a <trova_targhet+0xca>
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jne    11de <trova_targhet+0x9e>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11fc <trova_targhet+0xbc>
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a6 <trova_targhet+0x66>
jmp    121b <trova_targhet+0xdb>
lea    0xe02(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x14(%rbp)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trova_targhet>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xea4(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119b <trova_targhet+0x5b>
lea    0xe9a(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmp    %r14d,0xc(%rsp)
jae    119b <trova_targhet+0x5b>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
jmp    11e9 <trova_targhet+0xa9>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     11e9 <trova_targhet+0xa9>
movslq %r14d,%rbp
xor    %ebx,%ebx
lea    0xe65(%rip),%r14
jmp    11c9 <trova_targhet+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    %eax,%ecx
jae    11e9 <trova_targhet+0xa9>
mov    %ebx,%ecx
mov    (%r12,%rcx,8),%rcx
mov    (%rcx,%rbp,4),%esi
mov    %eax,%ecx
cmp    %r15d,%esi
je     11c0 <trova_targhet+0x80>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%eax
mov    %ebx,%ecx
jmp    11c0 <trova_targhet+0x80>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"tabelle.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%u %u\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [27 x i8] c"numero colonna inesistente\00"
define i32 @trova_targhet(i32** %0, i32 %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 -1, i32* %7
%12 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32*, i32** %8
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %9, i32* %10)
br label %18
18: ; preds = %15, %3
%19 = load i32, i32* %5
%20 = load i32, i32* %10
%21 = icmp ule i32 %19, %20
br i1 %21, label %22, label %57
22: ; preds = %18
store i32 0, i32* %11
br label %23
23: ; preds = %53, %22
%24 = load i32, i32* %11
%25 = load i32, i32* %9
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %56
27: ; preds = %23
%28 = load i32**, i32*** %4
%29 = load i32, i32* %11
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32*, i32** %28, i64 %30
%32 = load i32*, i32** %31
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %6
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %27
%40 = load i32, i32* %11
store i32 %40, i32* %7
%41 = load i32, i32* %9
store i32 %41, i32* %11
br label %53
42: ; preds = %27
%43 = load i32**, i32*** %4
%44 = load i32, i32* %11
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i32*, i32** %43, i64 %45
%47 = load i32*, i32** %46
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %42, %39
%54 = load i32, i32* %11
%55 = add i32 %54, 1
store i32 %55, i32* %11
br label %23
56: ; preds = %23
br label %59
57: ; preds = %18
%58 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %56
store i32 1, i32* %7
ret i32 1
}

LLVM IR (-O2):
@.str = [12 x i8] c"tabelle.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%u %u\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [27 x i8] c"numero colonna inesistente\00"
define i32 @trova_targhet(i32** nocapture %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%12 = load i32, i32* %5
%13 = icmp ult i32 %12, %1
br i1 %13, label %36, label %14
14: ; preds = %3, %10
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %38, label %17
17: ; preds = %14
%18 = sext i32 %1 to i64
br label %19
19: ; preds = %17, %31
%20 = phi i32 [ %15, %17 ], [ %32, %31 ]
%21 = phi i32 [ 0, %17 ], [ %34, %31 ]
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i32*, i32** %0, i64 %22
%24 = load i32*, i32** %23
%25 = getelementptr inbounds i32, i32* %24, i64 %18
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, %2
br i1 %27, label %31, label %28
28: ; preds = %19
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%30 = load i32, i32* %4
br label %31
31: ; preds = %19, %28
%32 = phi i32 [ %30, %28 ], [ %20, %19 ]
%33 = phi i32 [ %21, %28 ], [ %20, %19 ]
%34 = add i32 %33, 1
%35 = icmp ult i32 %34, %32
br i1 %35, label %19, label %38
36: ; preds = %10
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %31, %14, %36
ret i32 1
}