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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_mac_from_ip(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *);
scalar_t__ strcasestr(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ system(char *);
void get_model_name_from_UA(char *ua, char *ip) {
  FILE *fp;
  char line[256], *newline, *sku, *model, *type, mac[32], cmd[512];
  fp = fopen("/tmp/device_tables/UA.csv", "r");
  if (!fp)
    return;
  memset(mac, 0, 32);
  while (fgets(line, sizeof(line), fp)) {
    newline = strtok(line, "\n");
    sku = strtok(newline, ",");
    model = strtok(NULL, ",");
    type = strtok(NULL, ",");
    if (strcasestr(ua, sku)) {
      ;
      get_mac_from_ip(mac, ip);
      if (mac[0] != '\0') {
        ;
        snprintf(cmd, sizeof(cmd), "devices_info update \"%s\" \"%s\" \"%s\"",
                 mac, type, model);
        system(cmd);
      }
      break;
    }
  }
  fclose(fp);
  return;
}


x86 assembly (clang, -O0):
<get_model_name_from_UA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe56(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ca <get_model_name_from_UA+0x3a>
jmp    12e4 <get_model_name_from_UA+0x154>
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12db <get_model_name_from_UA+0x14b>
lea    -0x120(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x130(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xde3(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x138(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdcc(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x140(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   10b0 <strcasestr@plt>
cmp    $0x0,%rax
je     12d6 <get_model_name_from_UA+0x146>
lea    -0x160(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <get_mac_from_ip@plt>
movsbl -0x160(%rbp),%eax
cmp    $0x0,%eax
je     12d1 <get_model_name_from_UA+0x141>
lea    -0x360(%rbp),%rdi
lea    -0x160(%rbp),%rcx
mov    -0x140(%rbp),%r8
mov    -0x138(%rbp),%r9
mov    $0x200,%esi
lea    0xd60(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x360(%rbp),%rdi
call   1040 <system@plt>
jmp    12db <get_model_name_from_UA+0x14b>
jmp    11dd <get_model_name_from_UA+0x4d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_model_name_from_UA>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x338,%rsp
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe52(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     129f <get_model_name_from_UA+0x10f>
mov    %rbx,0x8(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    0x30(%rsp),%rbx
lea    0xe35(%rip),%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    (%rsp),%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1296 <get_model_name_from_UA+0x106>
mov    %rbx,%rdi
lea    0xe08(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,%rdi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %r15,%rsi
call   10b0 <strcasestr@plt>
test   %rax,%rax
je     11f0 <get_model_name_from_UA+0x60>
lea    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1060 <get_mac_from_ip@plt>
cmpb   $0x0,0x10(%rsp)
je     1296 <get_model_name_from_UA+0x106>
lea    0xdb2(%rip),%rdx
lea    0x130(%rsp),%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r13,%r8
mov    %r14,%r9
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    (%rsp),%rdi
call   1030 <fclose@plt>
add    $0x338,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"/tmp/device_tables/UA.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [35 x i8] c"devices_info update \22%s\22 \22%s\22 \22%s\22\00"
define void @get_model_name_from_UA(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [32 x i8]
%12 = alloca [512 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
br label %57
17: ; preds = %2
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 32)
br label %20
20: ; preds = %53, %17
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i64 @fgets(i8* %21, i32 256, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %54
25: ; preds = %20
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = call i8* @strtok(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i8* @strtok(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %29, i8** %8
%30 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %30, i8** %9
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %31, i8** %10
%32 = load i8*, i8** %3
%33 = load i8*, i8** %8
%34 = call i64 @strcasestr(i8* %32, i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %53
36: ; preds = %25
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%38 = load i8*, i8** %4
%39 = call i32 @get_mac_from_ip(i8* %37, i8* %38)
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %36
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%47 = load i8*, i8** %10
%48 = load i8*, i8** %9
%49 = call i32 @snprintf(i8* %45, i32 512, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %47, i8* %48)
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%51 = call i32 @system(i8* %50)
br label %52
52: ; preds = %44, %36
br label %54
53: ; preds = %25
br label %20
54: ; preds = %52, %20
%55 = load i32*, i32** %5
%56 = call i32 @fclose(i32* %55)
br label %57
57: ; preds = %54, %16
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"/tmp/device_tables/UA.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [35 x i8] c"devices_info update \22%s\22 \22%s\22 \22%s\22\00"
define void @get_model_name_from_UA(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [32 x i8]
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %32, label %11
11: ; preds = %2
%12 = call i32 @memset(i8* %7, i32 0, i32 32)
br label %13
13: ; preds = %16, %11
%14 = call i64 @fgets(i8* %6, i32 256, i32* %9)
%15 = icmp eq i64 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %13
%17 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = call i64 @strcasestr(i8* %0, i8* %18)
%22 = icmp eq i64 %21, 0
br i1 %22, label %13, label %23
23: ; preds = %16
%24 = call i32 @get_mac_from_ip(i8* %7, i8* %1)
%25 = load i8, i8* %7
%26 = icmp eq i8 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = call i32 @snprintf(i8* %8, i32 512, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* %20, i8* %19)
%29 = call i32 @system(i8* %8)
br label %30
30: ; preds = %13, %23, %27
%31 = call i32 @fclose(i32* %9)
br label %32
32: ; preds = %2, %30
ret void
}