#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int is_hex(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int my_set_outputs(char *filename, int fd) {
  FILE *fp;
  char first;
  char buf[100];
  char send[100];
  int i, n;
  if ((fp = fopen(filename, "r")) == NULL) {
    return (-1);
  }
  if (fgets(buf, 99, fp) != NULL) {
    if ((i = is_hex(&buf[0])) >= 0) {
      n = i & 0xf;
      sprintf(send, "L%01x%01x\n", n, n);
      printf("%s", send);
    }
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<my_set_outputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119c <my_set_outputs+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <my_set_outputs+0xcc>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x63,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     121c <my_set_outputs+0xbc>
lea    -0x90(%rbp),%rdi
call   1050 <is_hex@plt>
mov    %eax,-0x104(%rbp)
cmp    $0x0,%eax
jl     1217 <my_set_outputs+0xb7>
mov    -0x104(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x108(%rbp),%edx
mov    -0x108(%rbp),%ecx
lea    0xe03(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x100(%rbp),%rsi
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
jmp    121c <my_set_outputs+0xbc>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_set_outputs>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d5 <my_set_outputs+0x75>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x63,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11c9 <my_set_outputs+0x69>
mov    %rsp,%rdi
call   1050 <is_hex@plt>
test   %eax,%eax
js     11c9 <my_set_outputs+0x69>
and    $0xf,%eax
lea    0xe59(%rip),%rsi
lea    0x70(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%edx
mov    %eax,%ecx
call   1080 <sprintf@plt>
lea    0xe4c(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11da <my_set_outputs+0x7a>
mov    $0xffffffff,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"L%01x%01x\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @my_set_outputs(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8
%8 = alloca [100 x i8]
%9 = alloca [100 x i8]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %38
16: ; preds = %2
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32* @fgets(i8* %17, i32 99, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%23 = call i32 @is_hex(i8* %22)
store i32 %23, i32* %10
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i32, i32* %10
%27 = and i32 %26, 15
store i32 %27, i32* %11
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* %11
%30 = load i32, i32* %11
%31 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %25, %21
br label %35
35: ; preds = %34, %16
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %15
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"L%01x%01x\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @my_set_outputs(i8* nocapture %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = call i32* @fgets(i8* %5, i32 99, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = call i32 @is_hex(i8* %5)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = and i32 %13, 15
%17 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %19
19: ; preds = %12, %15, %9
%20 = call i32 @fclose(i32* %7)
br label %21
21: ; preds = %2, %19
%22 = phi i32 [ 0, %19 ], [ -1, %2 ]
ret i32 %22
}