#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*/ filename;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EACCES;
int atoi(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strncmp(char const *, char *, int);
int handle_csense_reply(const char *line) {
  if (strncmp(line, "CSENSE ", 7) == 0) {
    int senseline = atoi(line + 7);
    int current = atoi(line + 9);
    printf("current consumption on line %i: %i units\n", senseline, current);
    FILE *f;
    char filename[128];
    snprintf(filename, sizeof(filename), "/tmp/telemetry.csense.%i", senseline);
    f = fopen(filename, "w");
    if (!f) {
      perror(filename);
      return -EACCES;
    }
    fprintf(f, "%i\n", current);
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<handle_csense_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1258 <handle_csense_reply+0xd8>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x9,%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe2d(%rip),%rdi
call   1050 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x80,%esi
lea    0xe3c(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123c <handle_csense_reply+0xbc>
lea    -0xa0(%rbp),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
mov    0x2db6(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    125f <handle_csense_reply+0xdf>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe03(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_csense_reply>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbp
lea    0xe69(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    121d <handle_csense_reply+0x9d>
lea    0x7(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
add    $0x9,%rbp
mov    %rbp,%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
lea    0xe3e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <printf@plt>
lea    0xe58(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %ebx,%ecx
call   1060 <snprintf@plt>
lea    0xe58(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     122e <handle_csense_reply+0xae>
mov    %rax,%rbp
lea    0xe43(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r15d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rdi
call   1090 <perror@plt>
mov    0x2dab(%rip),%rax
xor    %r15d,%r15d
sub    (%rax),%r15d
jmp    121d <handle_csense_reply+0x9d>

LLVM IR (-O0):
@.str = [8 x i8] c"CSENSE \00"
@.str.1 = [42 x i8] c"current consumption on line %i: %i units\0A\00"
@.str.2 = [25 x i8] c"/tmp/telemetry.csense.%i\00"
@.str.3 = [2 x i8] c"w\00"
@EACCES = global i32 0
@.str.4 = [4 x i8] c"%i\0A\00"
define i32 @handle_csense_reply(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [128 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %39
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 7
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %4
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 9
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%22 = load i32, i32* %4
%23 = call i32 @snprintf(i8* %21, i32 128, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %33, label %28
28: ; preds = %11
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%30 = call i32 @perror(i8* %29)
%31 = load i32, i32* @EACCES
%32 = sub nsw i32 0, %31
store i32 %32, i32* %2
br label %40
33: ; preds = %11
%34 = load i32*, i32** %6
%35 = load i32, i32* %5
%36 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %33, %1
store i32 0, i32* %2
br label %40
40: ; preds = %39, %28
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [8 x i8] c"CSENSE \00"
@.str.1 = [42 x i8] c"current consumption on line %i: %i units\0A\00"
@.str.2 = [25 x i8] c"/tmp/telemetry.csense.%i\00"
@.str.3 = [2 x i8] c"w\00"
@EACCES = global i32 0
@.str.4 = [4 x i8] c"%i\0A\00"
define i32 @handle_csense_reply(i8* %0) {
%2 = alloca [128 x i8]
%3 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 7
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8, i8* %0, i64 9
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%12 = call i32 @snprintf(i8* %11, i32 128, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%13 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %5
%16 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%17 = call i32 @fclose(i32* %13)
br label %22
18: ; preds = %5
%19 = call i32 @perror(i8* %11)
%20 = load i32, i32* @EACCES
%21 = sub nsw i32 0, %20
br label %22
22: ; preds = %1, %15, %18
%23 = phi i32 [ %21, %18 ], [ 0, %15 ], [ 0, %1 ]
ret i32 %23
}