#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 *, ...);
int urg_serial_find_port();
scalar_t__ urg_serial_is_urg_port(int);
char *urg_serial_port_name(int);
int main(void) {
  int found_port_size = urg_serial_find_port();
  int i;
  if (found_port_size == 0) {
    printf("could not found ports.\n");
    return 1;
  }
  for (i = 0; i < found_port_size; ++i) {
    printf("%s", urg_serial_port_name(i));
    if (urg_serial_is_urg_port(i)) {
      printf(" [URG]");
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <urg_serial_find_port@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    117d <main+0x3d>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ec <main+0xac>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e5 <main+0xa5>
mov    -0xc(%rbp),%edi
call   1030 <urg_serial_port_name@plt>
mov    %rax,%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <urg_serial_is_urg_port@plt>
cmp    $0x0,%rax
je     11c9 <main+0x89>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1184 <main+0x44>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <urg_serial_find_port@plt>
test   %eax,%eax
je     11cd <main+0x6d>
jle    11e2 <main+0x82>
mov    %eax,%ebx
lea    0xe81(%rip),%r14
lea    0xe7d(%rip),%r15
xor    %ebp,%ebp
jmp    11a1 <main+0x41>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
je     11e0 <main+0x80>
mov    %ebp,%edi
call   1050 <urg_serial_port_name@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   1080 <urg_serial_is_urg_port@plt>
test   %rax,%rax
je     1190 <main+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1190 <main+0x30>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    11e2 <main+0x82>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"could not found ports.\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c" [URG]\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @urg_serial_find_port()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %29
9: ; preds = %0
store i32 0, i32* %3
br label %10
10: ; preds = %25, %9
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i8* @urg_serial_port_name(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %3
%19 = call i64 @urg_serial_is_urg_port(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %10
28: ; preds = %10
store i32 0, i32* %1
br label %29
29: ; preds = %28, %7
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c" [URG]\00"
@str = [23 x i8] c"could not found ports.\00"
define i32 @main() {
%1 = tail call i32 (...) @urg_serial_find_port()
%2 = icmp eq i32 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = icmp sgt i32 %1, 0
br i1 %4, label %7, label %19
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %19
7: ; preds = %3, %15
%8 = phi i32 [ %17, %15 ], [ 0, %3 ]
%9 = tail call i8* @urg_serial_port_name(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i64 @urg_serial_is_urg_port(i32 %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = tail call i32 @putchar(i32 10)
%17 = add nuw nsw i32 %8, 1
%18 = icmp eq i32 %17, %1
br i1 %18, label %19, label %7
19: ; preds = %15, %3, %5
%20 = phi i32 [ 1, %5 ], [ 0, %3 ], [ 0, %15 ]
ret i32 %20
}