#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*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int set_input(char *str, int *n) {
  FILE *f_in;
  int err = 0;
  if ((f_in = fopen("in.txt", "r")) != NULL) {
    err += (fscanf(f_in, "%s\n%i", str, n) < 0) ? 4 : 0;
    fclose(f_in);
  } else
    err = 1;
  return err;
}


x86 assembly (clang, -O0):
<set_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb2(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a5 <set_input+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe8e(%rip),%rsi
call   1040 <fscanf@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x4,%ecx
cmp    $0x0,%rdx
cmovl  %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11ac <set_input+0x7c>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_input>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xebb(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1182 <set_input+0x52>
mov    %rax,%r12
lea    0xea9(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <fscanf@plt>
mov    %rax,%rbx
shr    $0x3d,%rbx
and    $0xfffffffc,%ebx
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    1187 <set_input+0x57>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"in.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%s\0A%i\00"
define i32 @set_input(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %6
%7 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = load i32*, i32** %5
%11 = load i8*, i8** %3
%12 = load i32*, i32** %4
%13 = call i64 @fscanf(i32* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %11, i32* %12)
%14 = icmp slt i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 4, i32 0
%17 = load i32, i32* %6
%18 = add nsw i32 %17, %16
store i32 %18, i32* %6
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
br label %22
21: ; preds = %2
store i32 1, i32* %6
br label %22
22: ; preds = %21, %9
%23 = load i32, i32* %6
ret i32 %23
}

LLVM IR (-O2):
@.str = [7 x i8] c"in.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%s\0A%i\00"
define i32 @set_input(i8* %0, i32* %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* %1)
%7 = lshr i64 %6, 61
%8 = trunc i64 %7 to i32
%9 = and i32 %8, 4
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %2, %5
%12 = phi i32 [ %9, %5 ], [ 1, %2 ]
ret i32 %12
}